Python class variable name vs __name__ -


i'm trying understand relationship between variable python class object assigned , __name__ attribute class object. example:

in [1]: class foo(object):    ...:     pass    ...:   in [2]: foo.__name__ = 'bar'  in [3]: foo.__name__ out[3]: 'bar'  in [4]: foo out[4]: __main__.bar  in [5]: bar --------------------------------------------------------------------------- nameerror                                 traceback (most recent call last) <ipython-input-5-962d3beb4fd6> in <module>() ----> 1 bar  nameerror: name 'bar' not defined 

so seems have changed __name__ attribute of class can't refer name. know bit general explain relationship between foo , foo.__name__?

it's simple. there no relationship @ all.

when create class local variable created name used, pointing @ class can use it.

the class gets attribute __name__ contains name of variable, because that's handy in cases, pickling.

you can set local variable else, or change __name__ variable, things pickling won't work, don't that.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -