>>> class Foo:
... 'it is a example'
... print 'i am here'
...
i am here
>>> Foo.__name__
'Foo'
>>> Foo().__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: Foo instance has no attribute '__name__'
>>> Foo.__doc__
'it is a example'
>>> Foo().__doc__
'it is a example'
>>> Foo.__dict__
{'__module__': '__main__', '__doc__': 'it is a example'}
>>> Foo().__dict__
{}
>>> Foo.__module__
'__main__'
>>> Foo().__module__
'__main__'
>>> myname=Foo()
>>> myname.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: Foo instance has no attribute `__name__`
What is the reason instances have no attribute __name__
?
maybe it is ok that the __name__
of instance-myname is myname
.
would you mind tell me more logical, not the unreasonable grammar rules?
__name__
attribute on instances? The relevant documentation says it exists for classes (and other things), but I don't see any mention of it for instances. – Dulcie__name__
is the name of a "class or type", not an instance of a class or type. Why should instances have__name__
s? – AlcottFoo().__class__.__name__
? – Feu