I wrote following code:
class node:
def __init__(self, title, series, parent):
self.series = series
self.title = title
self.checklist = []
if(parent != None):
self.checklist = parent.checklist
self.checklist.append(self)
When I create objects like this:
a = node("", s, None)
b = node("", s, a)
print a.checklist
Unexpectedly, it shows both a and b objects as an output of print statement. I am new to python. So, possibly there's some stupid mistake.
Thank you.
self.checklist = parent.checklistshould raise AttributeError if parent=None, I think it should be in if statement. And also, useparent is not Noneinstead of!=and don't use parantheses with if statement(with one condition).