Reputation: 277
Here's my code:
class Node:
def __init__(self, cargo=None, next=None):
self.cargo = cargo
self.next = next
class LinkedList:
def __init__(self):
self.first = None
self.last = None
# then I declare a list and a node
S = LinkedList()
cel = Node
cel = S.first
Now I want to put something in the list:
n = 0
x = 0
while n < 5:
x = input()
cel.val = x
cel = cel.next
Yet I get an error stating that:
'NoneType' object has no attribute 'val'
'NoneType' object has no attribute 'next'
Where is the problem?
Upvotes: 0
Views: 1686
Reputation: 4606
cel
is equal to S.first
. S.first
is equal to None
.
When you try to get val
from cel
m you try to get val
attribute of None
.
And none of you classes has val
attribute... So it is possible to assign it, but I'd suggest to avoid it, because it is not clear to create it somewhere without declaring it in class itself.
Upvotes: 1