>>> class Test(object):
... test = {}
...
>>> class Test2(Test):
... pass
...
>>> Test2.test.update({1:2})
>>> Test.test
{1: 2}
>>>
I was expecting {}. Happens also with old style classes.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s nothing odd with how
updateworks. The point is thattestis a class attribute, and class attributes are shared between classes, (untill someone rebindstestto something else).Take a look at this IDE session:
For further informations on how class attributes works look at Data Model Reference under Classes.