File "C:\Users\USER\Desktop\myList2.py", line 44, in mkListNode
listNode.next = next
AttributeError: 'ListNode' object attribute 'next' is read-only
それが何を意味するのかわかりません。以下は、myList.py のコード全体です。ありがとう
class ListNode():
"""
All true value-containing wheel nodes are represented as
instances of ListNode.
"""
__slots__ = ('data', 'next', 'prev')
class MyList():
"""
The container for a linked wheel class.
It contains a reference to a cursor in the wheel.
Invariant: size==0 iff type(cursor)==EmptyListNode
"""
__slots__ = ('cursor', 'size')
def mkListNode(data, next, prev):
"""
Make a new list node
Returns a new node
"""
listNode = ListNode()
listNode.data = data
listNode.next = next
listNode.prev = prev
return ListNode
def add(myList, element):
"""
add: Add a node to the wheel right after the cursor
Effect: A new node is in the wheel just after the cursor
"""
myList.size += 1
if myList.cursor == EmptyListNode:
myList.cursor = mkListNode(EmptyListNode, element, EmptyListNode)
myList.cursor.prev = myList.cursor
myList.cursor.next = myList.cursor
else:
temp = mkListNode(myList.cursor.prev, element, myList.cursor.next)
myList.cursor.prev.next = temp
myList.cursor.prev = temp
ListNode が読み取り専用になる理由がわかりません。うーん、興味深いことに、オブジェクト属性について読み取り専用をシードすることはありません。