Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何修复此AttributeError_Python_Oop - Fatal编程技术网

Python 如何修复此AttributeError

Python 如何修复此AttributeError,python,oop,Python,Oop,我试图访问类中函数中的变量并打印它。每当我尝试时,总是会出现错误:AttributeError:“NoneType”对象没有属性“job\u ID” def driver(): q = my_queue.Queue_() for line in df: if 'received' in line: q.enqueue(line) print("Adding job " + q.new_item.job_ID + "

我试图访问类中函数中的变量并打印它。每当我尝试时,总是会出现错误:AttributeError:“NoneType”对象没有属性“job\u ID”

def driver():
    q = my_queue.Queue_()
    for line in df:
        if 'received' in line:
            q.enqueue(line)
            print("Adding job " + q.new_item.job_ID + " to the queue with the timestamp: " + q.new_item.time_stamp + ".")
            print("The prority of the job is: " + q.new_item.job_priority)
            print("The job type is: " + q.new_item.job_type)
        if 'respond' in line:
            q.dequeue()
            print("Completed job " + q.current.job_ID + " in " + str(int(q.time_elapsed)) + " seconds.")
        if 'active' in line:
            q.active_jobs()
            print("Total number of jobs: " + str(len(q.temp)))
            print("Average priority: " + str(q.average))
        if 'modify' in line:
            q.modify(line)
            print("Modified job " + q.current.job_ID)
此错误来自此代码中的最后一个print语句

这是此处使用的类中的函数:

def modify(self, x): # need to fix printing bug
        self.current = self.head
        while self.current != None:
            if x[1] in self.current.get_data():
                self.current.data[2] = x[2]
                self.current.data[3] = x[3]
                break
                # print("Modified job " + current.job_ID)
            else:
                # print('The job details cannot be modified.')
                pass
            self.current = self.current.get_next()

您提供的
modify
函数中循环的退出条件是
self.current==None

在最后一条条件语句中调用
modify()
时:

if 'modify' in line:
        q.modify(line) // here
        print("Modified job " + q.current.job_ID)
您正在将
q.current
计算为
None
。因此,您获得
属性错误的原因是
q.current
None
,它没有称为
job\u ID
的属性


要解决问题,必须确保打印
q.current.job\u ID
之前
q.current
不是
None
。除此之外,我无法为您提供任何帮助,因为我不知道您程序的用途。

您提供的
modify
函数中循环的退出条件是
self.current==None

在最后一条条件语句中调用
modify()
时:

if 'modify' in line:
        q.modify(line) // here
        print("Modified job " + q.current.job_ID)
您正在将
q.current
计算为
None
。因此,您获得
属性错误的原因是
q.current
None
,它没有称为
job\u ID
的属性


要解决问题,必须确保打印
q.current.job\u ID
之前
q.current
不是
None
。除此之外,我无法为您提供任何帮助,因为我不知道您的程序的用途。

while循环的条件是
while self.current!=无
,这就是为什么我们知道当
modify()
完成运行时,
self.current
None
。由于您正在对变量
q
调用
modify()
方法,
q.current
将是
None
。由于没有任何代码行明确地将
self.current
计算为
None
,因此它必须是
。get\u next()
使while循环具有条件
while self.current!=None的方法无
,这就是为什么我们知道当
modify()
完成运行时,
self.current
None
。由于您正在对变量
q
调用
modify()
方法,
q.current
将是
None
。由于没有任何代码行明确地将
self.current
计算为
None
,因此必须是
使
self.current==None
的方法