[Python-ideas] Fwd: Define a method or function attribute outside of a class with the dot operator
thomas at kluyver.me.uk
Fri Feb 10 07:02:56 EST 2017
On Fri, Feb 10, 2017, at 11:05 AM, Chris Angelico wrote:
> * What would the __name__ be? In "def ham.spam():", is the name "spam"
> or "ham.spam"? Or say you have "def x():" - is the name "x" or
> something else?
I'd say 'spam' in the first case, and a special value like '<unnamed
function>' in the latter. You already can't rely on __name__ being a
usable name in arbitrary callables:
x = lambda: 0
x.__name__ == '<lambda>'
More information about the Python-ideas