KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following seems strange.. Basically, the somedata attribute seems shared between all the classes that inherited from the_base_class . class the_base_class: somedata = {} somedata['was_false_in_base'] = False class subclassthing(the_base_class): def __init__(self): print self.somedata first = subclassthing() {'was_false_in_base': False} first.somedata['was_false_in_base'] = True second = subclassthing() {'was_false_in_base': True} >>> del first >>> del second >>> third = subclassthing() {'was_false_in_base': True} Defining self.somedata in the __init__ function is obviously the correct way to get around this (so each class has it's own somedata dict) - but when is such behavior desirable?
Tags (comma-separated)
Save Edits
Cancel