AttributeError: 'builtin_function_or_method' object has no attribute 'data'
AttributeError: 'builtin_function_or_method' object has no attribute 'data'
我试图在排序的链表中插入一个节点,插入后遍历它时显示属性错误。它正在插入节点并遍历,但最后它抛出错误。有人可以解释这里有什么问题吗?
def traversal(head):
curNode = head
while curNode is not None:
print(curNode.data , end = '->')
curNode = curNode.next
def insertNode(head,value):
predNode = None
curNode = head
while curNode is not None and curNode.data < value:
predNode = curNode
curNode = curNode.next
newNode = ListNode(value)
newNode.next = curNode
if curNode == head:
head = newNode
else:
predNode.next = newNode
return head
'builtin_function_or_method' object has no attribute 'x'
通常意味着您忘记将 ()
添加到函数调用中,例如
>>> 'thing'.upper.replace("H", "") #WRONG
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'replace'
>>> "thing".upper().replace("H", "") #RIGHT
'TING'
虽然你的代码看起来是正确的,但我认为调用 traversal
和 insertNode
的任何东西都试图将函数的结果作为参数传递,但它传递的是函数(它缺少 ()
)
我试图在排序的链表中插入一个节点,插入后遍历它时显示属性错误。它正在插入节点并遍历,但最后它抛出错误。有人可以解释这里有什么问题吗?
def traversal(head):
curNode = head
while curNode is not None:
print(curNode.data , end = '->')
curNode = curNode.next
def insertNode(head,value):
predNode = None
curNode = head
while curNode is not None and curNode.data < value:
predNode = curNode
curNode = curNode.next
newNode = ListNode(value)
newNode.next = curNode
if curNode == head:
head = newNode
else:
predNode.next = newNode
return head
'builtin_function_or_method' object has no attribute 'x'
通常意味着您忘记将 ()
添加到函数调用中,例如
>>> 'thing'.upper.replace("H", "") #WRONG
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'replace'
>>> "thing".upper().replace("H", "") #RIGHT
'TING'
虽然你的代码看起来是正确的,但我认为调用 traversal
和 insertNode
的任何东西都试图将函数的结果作为参数传递,但它传递的是函数(它缺少 ()
)