Python Forum
AttributeError Traceback (most recent call last)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError Traceback (most recent call last)
#1
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:

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...
Reply
#2
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.
Reply
#3
(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=td
so 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
Reply
#4
(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.

My line 41 is :
td, cdata = self.dataqueue.pop(0)
and there is nothing related to name. And my 43 line is:
self.lastt=td
so 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

BUt ok I understood now. Your mean is 31 and 33 lines and I corrected it now and it is ok. THanks :)
Reply
#5
I used the line numbers from the error trace.
Reply
#6
(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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Where to look to find the most recent Python grammar allusernametaken 9 3,496 Oct-04-2019, 04:12 AM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020