I notice python won't let you add an instance of a class to itself as a static member at class definition.
>>> class Foo:
... A = Foo()
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in Foo
NameError: name 'Foo' is not defined
However either of the following work:
>>> class Foo:
... pass
...
>>> class Foo:
... A = Foo()
...
>>> Foo.A
<__main__.Foo instance at 0x100854440>
or
>>> class Foo:
... pass
...
>>> Foo.A = Foo()
>>>
>>> Foo.A
<__main__.Foo instance at 0x105843440>
I can't find any enlightening code examples or explanations. Why does python treat the first case differently? Where is A going in each of the two subsequent cases?