Hi All,
I've got a problem with the python
class. I want to create a list of object of type obj() and link them such
that the next of one object is the next in its place order. I tried this
construction
class obj:
------def __init__(self,cargo=None,next=None):
---------------self.next = next
---------------self.cargo = cargo
class circular:
------def __init__(self,next=None):
---------------self.next = next
---------------self.quad = [obj(),obj(),obj(),obj()]
---------------for i in range(3):
self.quad[i].next = self.quad[i+1]
self.quad[3].next = self.quad[0]
when I run it,
>>>a = circular()
>>>a.quad=[obj(1),obj(2),obj(3),obj(4)]
>>>print a.quad[0].next.cargo
None
which is not the link that I think, rather I have to do this
class obj:
def __init__(self,cargo=None,next=None):
self.next = next
self.cargo = cargo
class circular:
def __init__(self,next=None):
self.next = next
self.quad = [obj(),obj(),obj(),obj()]
def setlink(self):
for i in range(3):
self.quad[i].next = self.quad[i+1]
self.quad[3].next = self.quad[0]
>>>>a = circular()
>>>a.quad=[obj(1),obj(2),obj(3),obj(4)]
>>>a.setlink()
>>>print a.quad[0].next.cargo
2
which is not very practical since we have to set always the link, is there
any possibility of link them automaticaly?
regards
Faniry