get the name of lambda

Michael Hoffman m.h.3.9.1.without.dots.at.cam.ac.uk at example.com
Sat Oct 16 13:32:43 EDT 2004


George Yoshida wrote:

> 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.

To be honest, I think munging the func_name attribute is a silly way to 
get what you want :)

> I was doing something like:
> 
> for func in (func1, func2, func3):
>     print func.func_name
>     print measure_ellapsed_time(func)

How about:

funcs = dict(func1=func1, func2=func2, func3=lambda: None)
for name, func in funcs.iteritems():
     print name
     print measure_elapsed_time(func)
-- 
Michael Hoffman



More information about the Python-list mailing list