The following are my class definitions :
class logline:
def __init__(self,t,cmp,msg):
self.t = t
self.cmp = cmp
self.msg = msg
class cluster:
clusters = []
def __init__(self,status,log):
self.status = status
self.children = []
self.eventlogs = []
self.rep_msg = log.msg
self.addLog(log)
self.prev = None
if(status == 'root'):
cluster.clusters.append(self)
def prev(self):
return self.prev
def print_children(self):
for child in range(0,len(self.children)):
print(self.children[child].rep_msg)
self.children[child].print_logs()
def print_logs(self):
for log in self.eventlogs:
print(log.msg)
def add_child(self,status,log):
temp = cluster(status,log)
self.children.append(temp)
temp.prev=self
return temp
def addLog(self,log):
self.eventlogs.append(log)
Now, tree is my root cluster node
tree = cluster('root',log1)
and prev is my child cluster node added to tree
tree = tree.add_child('child',log6)
When I try:
tree = tree.prev()
I should get back tree, but it gives me the error:
tree = tree.prev()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'cluster' object is not callable
On the other hand :
callable(cluster)
evaluates to true
my class definitions are based off of: How can I implement a tree in Python? Are there any built in data structures in Python like in Java?
I've searched around but can't seem to find anything which matches my situation
Thanks in advance
Edit : So, I am an absolute beginner in python, I should have probably led with that
>>> print(tree)
<__main__.cluster object at 0x02AF8590>
>>> print(tree.prev)
<__main__.cluster object at 0x02AEA270>
I'm assuming since I'm getting different locations for both statements, prev has been set to something
But I'm not able to go back to my parent node with
return self.prev