Python 3.x AttributeError:type object';节点';没有属性';价值';

Python 3.x AttributeError:type object';节点';没有属性';价值';,python-3.x,attributeerror,Python 3.x,Attributeerror,你能帮我吗 当我使用pop时,我的代码会因为这个问题崩溃: 文件“C:\Users\ME\source\repos\PythonApplication2\PythonApplication2\PythonApplication2.py”,第28行,pop格式 返回self.tail.value AttributeError:type对象“Node”没有属性“value”推送函数没有创建具有任何值的Node对象 而不是 class Node(): def __init__(self, v

你能帮我吗

当我使用pop时,我的代码会因为这个问题崩溃: 文件“C:\Users\ME\source\repos\PythonApplication2\PythonApplication2\PythonApplication2.py”,第28行,pop格式 返回self.tail.value
AttributeError:type对象“Node”没有属性“value”

推送函数没有创建具有任何值的Node对象

而不是

class Node():

    def __init__(self, value):
        self.value = value
        self.prev = None
        self.next = None

class LinkedList():

    def __init__(self):
        self.head = None
        self.tail = None

    def push(self, item):
        new_node = Node
        if self.tail is None:
            self.head = self.tail = new_node
        else:
            new_node.prev = self.tail
            self.tail.next = new_node
            self.tail = new_node

    def pop(self):
        if self.tail is not None:
            if self.tail.prev is not None:
                self.tail = self.tail.prev
                self.tail.next = None
            else:
                self.tail = self.head = None
            return self.tail.value
        else:
            return None
你需要像这样的东西:

new_node = Node

原因是没有名为value的属性/类属性

尝试:

新建节点=节点(1)

其中1可以是任何值,并表示值


def\uuu init\uuu(self,value):

在类定义中不必使用括号()-
new_node = Node(5)  # pass in some value