This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients chuyi, eric.smith, paul.moore, steve.dower, tim.golden, zach.ware
Date 2019-10-15.07:47:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571125641.33.0.645728489533.issue38481@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-10-15 07:47:21eric.smithsetrecipients: + eric.smith, paul.moore, tim.golden, zach.ware, steve.dower, chuyi
2019-10-15 07:47:21eric.smithsetmessageid: <1571125641.33.0.645728489533.issue38481@roundup.psfhosted.org>
2019-10-15 07:47:21eric.smithlinkissue38481 messages
2019-10-15 07:47:21eric.smithcreate