>>> 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__`
인스턴스에 __name__
속성이없는 이유는 무엇입니까?
어쩌면 instance-myname의 __name__
이 myname
인 것이 좋습니다.
좀 더 논리적이지, 불합리한 문법 규칙이 아닌가요?왜 파이썬 인스턴스에 __name__ 속성이 없습니까?
인스턴스에 '__name__'속성이 있어야한다고 생각하는 이유는 무엇입니까? [관련 문서] (http://docs.python.org/2/reference/datamodel.html)에는 클래스 (및 다른 것들)에 대해 언급되어 있지만 인스턴스에 대한 언급은 없습니다. – Celada
[docs] (http://docs.python.org/2/library/stdtypes.html?highlight=__name__#class.__name__) : '__name__'은 (는) '클래스 또는 유형'의 이름입니다. 클래스 또는 유형의 인스턴스. 인스턴스에 '__name__'이 있어야하는 이유는 무엇입니까? –
'Foo() .__ class __.__ name__'을 원하셨습니까? –