Mar-28-2021, 01:04 AM
(This post was last modified: Mar-28-2021, 09:26 AM by Larz60+.
Edit Reason: added spacing between functions
)
Hello,
I created a class:
I created a class:
class inportProp: def __init__(self, t0, tM, incoming, phys, clinkdt, otherport=None, name=''): self.DEBUG=True self.lastt=t0 self.tM=tM if self.tM == 0: def updateqmem(t): pass else : def updateqmem(t): perase=-expm1(-(t-self.lastt)/self.tM) for i,q in enumerate(self.physqueue): if random()<perase: q.lost() del self.physqueue[i] self.updateqmem=updateqmem self.incoming=incoming self.phys=phys self.physqueue=[] self.dataqueue=[] self.clinkdt=clinkdt self.otherport=otherport if otherport != None: if otherport.otherport==None : otherport.otherport=self otherport.clinkdt=clinkdt else: raise ValueError(f"{otherport} already ok") self.nextitemin() self.otherport.nextitemin() self.name=name def __next__(self): while True: if len(self.dataqueue)==0: self.otherport.nextitemin() while self.lastt < self.dataqueue[0][0]: self.nextitemin() td, cdata = self.dataqueue.pop(0) self.updateqmem(td) self.lastt=td while len(self.physqueue)>0 and self.physqueue[0][1].idt<cdata: self.physqueue.pop(0) if len(self.physqueue)>0 and self.physqueue[0][1].idt==cdata: tq, qb = self.physqueue.pop(0) return [td, qb] def nextitemin(self): tq, q = next(self.incoming) self.updateqmem(tq) if self.phys==0 or len(self.physqueue)<=self.phys: self.physqueue.append([tq, q]) self.lastt=tq self.otherport.dataqueue.append([tq+self.clinkdt, q.idt]) if self.DEBUG : print(f'{self.name}.nextitemin') self.showstate() def showstate(self): print(f'{self.name}, t={self.lastt}') print(f'Physqueue:{self.physqueue}') print(f'Dataqueue:{self.dataqueue}')And when I test my class with this line:
inport1=inportProp(t0=0, tM=0, incoming=Abits, phys=10, clinkdt=4.7, name='A') inport2=inportProp(t0=0, tM=0, incoming=Bbits, phys=10, clinkdt=4.7, otherport=inport1, name='B') inport1.showstate() inport2.showstate() next(inport1)I have this error:
Error:4 inport1=inportProp(t0=0, tM=0, incoming=Abits, phys=10, clinkdt=4.7, name='A')
----> 5 inport2=inportProp(t0=0, tM=0, incoming=Bbits, phys=10, clinkdt=4.7, otherport=inport1, name='B')
6
7 inport1.showstate()
<ipython-input-61-d8c82b55cfef> in __init__(self, t0, tM, incoming, phys, clinkdt, otherport, name)
39 otherport.clinkdt=clinkdt
40 else: raise ValueError(f"{otherport} already ok")
---> 41 self.nextiteminin()
42 self.otherport.nextitemin()
43 self.name=name
<ipython-input-61-d8c82b55cfef> in nextitemin(self)
71 self.otherport.dataqueue.append([tq+self.clinkdt, q.idt])
72 if self.DEBUG :
---> 73 print(f'{self.name}.nextitemin')
74 self.showstate()
75 # pass
AttributeError: 'inportProp' object has no attribute 'name'
Where am I doing wrong? I have name attribute...