[Python-ideas] Fwd: Define a method or function attribute outside of a class with the dot operator

Thomas Kluyver 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[0]():" - is the name "x[0]" 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[0] = lambda: 0
x[0].__name__ == '<lambda>'


More information about the Python-ideas mailing list