I sometimes define an object variable outside of __init__
. plint
and my IDE (PyCharm) complain.
class MyClass():
def __init__(self):
self.nicevariable = 1 # everyone is happy
def amethod(self):
self.uglyvariable = 2 # everyone complains
plint
output:
W: 6, 8: Attribute 'uglyvariable' defined outside __init__ (attribute-defined-outside-init)
Why is this a incorrect practice?