finding name of instances created

Fredrik Lundh fredrik at pythonware.com
Mon Jan 24 07:34:07 EST 2005


Nick Coghlan wrote:

> Incidentally, this discussion made me realise the real reason why using a lambda to create a named 
> function is evil:
>
> Py> def f(): pass
> ...
> Py> f.func_name
> 'f'
> Py> f = lambda: None
> Py> f.func_name
> '<lambda>'
>
> I think I've heard that explanation before, but it never really clicked.

that's nothing you cannot fix, though:

    >>> f = lambda: None
    >>> f.func_name = "f"

    >>> f.func_name
    'f'

(only works in 2.4 and later, from what I can tell)

</F> 






More information about the Python-list mailing list