I have this (example) code:
init()
class A:
foo = bar()
def __init__(self):
print(A.foo)
The problem is, the function bar() refuses to work unless init() has been called first. What is a nice Pythonesque solution for this problem?
In my specific situation init() is third-party and can not be adapted and is called in a different file than A is defined.
Like this?
You could also move the
ifstatement toA.__new__()if you are not sureA.__init__()will be called (e.g. when unpickling anAobject before explicitly calling its constructor).