get the name of lambda
George Yoshida
ml at dynkin.com
Sat Oct 16 09:50:56 EDT 2004
Michael Hoffman wrote:
> Anyway I don't think it has anything to do with lambda:
>
> >>> def x(): pass
> ...
> >>> y = x
> >>> y.__name__
> 'x'
>
> IIRC, in 2.4 you can set the func_name attribute so you could set up a
> decorator to set the name for you. Or if you want to be fancy you could
> even set up a metaclass that automatically renames all the lambda
> functions it finds in a class.
I haven't had a chance to play with decorators, but I'll give
it a try. In any case, I don't need a fancy way.
The simpler, the better.
> But why?
I implemented a function in several ways(using recursion,
lambda, etc) and benchmarked them. In that script, I needed
to display function names, along with ellapsed time.
I was doing something like:
for func in (func1, func2, func3):
print func.func_name
print measure_ellapsed_time(func)
and get hit by lambda!
-- George
More information about the Python-list
mailing list