![]() |
AttributeError Traceback (most recent call last) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: AttributeError Traceback (most recent call last) (/thread-33085.html) |
AttributeError Traceback (most recent call last) - quest - Mar-28-2021 Hello, 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: Where am I doing wrong? I have name attribute...
RE: AttributeError Traceback (most recent call last) - deanhystad - Mar-28-2021 No you dont. Not yet. You don't have a name until line 43, but in line 41 you call a method that uses name. RE: AttributeError Traceback (most recent call last) - quest - Mar-28-2021 (Mar-28-2021, 01:37 AM)deanhystad Wrote: No you dont. Not yet. You don't have a name until line 43, but in line 41 you call a method that uses name. My line 41 is : td, cdata = self.dataqueue.pop(0)and there is nothing related to name. And my 43 line is: self.lastt=tdso I really do not understand what you are saying. There is nothing related to name in these lines and I also defined name in 33 line actually so it should not be a problem RE: AttributeError Traceback (most recent call last) - quest - Mar-28-2021 (Mar-28-2021, 10:01 AM)quest Wrote:(Mar-28-2021, 01:37 AM)deanhystad Wrote: No you dont. Not yet. You don't have a name until line 43, but in line 41 you call a method that uses name. BUt ok I understood now. Your mean is 31 and 33 lines and I corrected it now and it is ok. THanks :) RE: AttributeError Traceback (most recent call last) - deanhystad - Mar-28-2021 I used the line numbers from the error trace. RE: AttributeError Traceback (most recent call last) - quest - Mar-31-2021 (Mar-28-2021, 01:06 PM)deanhystad Wrote: I used the line numbers from the error trace. Can I send you a pm. I have a problem but it is a bit specific. I tried to send you a pm. But I am not allowed to do it or can I send you an email? |