[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Use cases for del
From:       Ron Adam <rrr () ronadam ! com>
Date:       2005-07-08 6:41:49
Message-ID: Nepze.220267$w15.195528 () tornado ! tampabay ! rr ! com
[Download RAW message or body]

Steven D'Aprano wrote:

> Ron Adam wrote:

>> def count_records(record_obj, start=0, end=len(record_obj)):
> 
> 
> That would work really well, except that it doesn't work at all.

Yep, and I have to stop trying to post on too little sleep.


Ok, how about... ?


def count_records(record_obj, start=0, end='to-end'):
     if end == 'to-end':
         end = len(record_obj)
     n = 0
     for rec in record_obj.data[start:end]:
         if not rec.isblank():
             n += 1
     return n


This isn't really different from using None. While it's possible to 
avoid None, its probably not worth the trouble.  I use it myself.


Here's something interesting:

import time

x = None
t = time.time()
for i in range(1000000):
     if x==None:
         pass
print 'None:',time.time()-t

x = 'to-end'
t = time.time()
for i in range(1000000):
     if x=='to-end':
         pass
print 'String:',time.time()-t

 >>>
None: 0.46799993515
String: 0.360000133514


Of course the difference this would make on a single call in practically 
Nill.

Anyway, time to call it a night so tomorrow I don't make anymore silly 
mistakes on comp.lang.python. :)

Cheers,
Ron

-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic