language-x-isms

Steve Holden steve at holdenweb.com
Thu Jun 8 06:22:16 EDT 2006


Alan Kennedy wrote:
> [Alan Kennedy]
> 
>>>On jython 2.1, I use something like this
>>>
>>>#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>>>try:
>>>  enumerate
>>>except NameError:
>>>  def enumerate(iterable):
>>>    results = [] ; ix = 0
>>>    for item in iterable:
>>>      results.append( (ix, item) )
>>>      ix = ix+1
>>>    return results
> 
> 
> [Fredrik Lundh]
> 
>>at least in CPython, using a user-defined enumerate function is a bit
>>slower than using the built-in version.
> 
> 
> Who's using a user-defined enumerate on cpython?
> 
> The above code only defines a user-defined enumerate when the built-in
> one doesn't exist, i.e. on jython, which raises NameError on reference
> to the non-existent enumerate.
> 
> On cpython, the reference to enumerate doesn't generate a NameError,
> therefore the user-supplied version never gets defined, and the builtin
> is used.
> 
You are assuming a relatively recent release of CPython. If you look at 
the stuff that the effbot distributes you will see that most of it 
supports CPython all the way back to 1.5.2. I don't think many of us 
have the right to be telling Fredrik what's pythonic and what's not ...

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list