Eric V. Smith <[email protected]> added the comment:
When you assign to self.num, you're creating an instance variable which hides
the class variable. Instead, assign directly to the class variable:
class D:
num = 0
def __init__(self):
D.num += 1
print('D num', self.num)
for i in range(5):
D()
D num 1
D num 2
D num 3
D num 4
D num 5
----------
nosy: +eric.smith
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38481>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com