I have noticed that static or object attributes in python can also be defined outside the class definition
class Test:
static_attr=201
def __init__(self):
self.object_attr=20
is the class definition and then we do:
t1=Test()
t2=Test()
t1.new_attr=200000
now after this
print(t1.new_attr)
prints 200000
print(t2.new_attr)
throws an error. To me this is a very counter-intuitive OOP concept, as it defeats the purpose of a class, because now each object can have a different set of attributes, even though those attributes are mapped out in .__dict__
. Is this bad coding practise in python?