Let's say I have a simple class:
class Foobar(object):
pass
If I use dir(Foobar)
, I'll get the following output:
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
Even though it does not appear in the output of dir()
, I can access __name__
:
Foobar.__name__
and get Foobar
.
Why does Python behave that way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…