why is self not passed to id()?

Ruediger larudwer at freenet.de
Thu Sep 4 23:06:30 CEST 2008


Fredrik Lundh wrote:

> 
>  >>> id
> <built-in function id>
>  >>> lambda x: id(x)
> <function <lambda> at 0x00C07C30>
> 
> any special reason why you're not using Python to write Python programs,
> btw?
> 
> </F>

I am aware that id is a built in function why shouldn't i use it?

Replaceing lambda with id was intended as an performance hack. Profiling
proofed that lambda itself takes more than twice as much cpu time than id
alone. (profile shortened)

         3610503 function calls in 22.451 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)

   960096    4.593    0.000    6.702    0.000 test14.py:33(<lambda>)
        1    0.003    0.003   22.451   22.451 {execfile}
   960096    2.109    0.000    2.109    0.000 {id}

However using lambda seemed useless to me since id already took an argument
and wrapping it in an python function simply has no real purpose.








More information about the Python-list mailing list