What is the most "pythonic" way to create a class member which is an instance of that class? I.e. something like this:
class MyClass:
# error! (and this is to be expected as MyClass is not yet fully defined)
instance_as_member = MyClass()
def __init__(self):
print("MyClass instance created!")
One can solve this by adding a member after the class definition:
class MyClass:
...
MyClass.instance_as_member = MyClass()
but this seems a little wrong; naturally, class members should be defined in that class.
Is there a better way to do this?