Reputation: 2560
I am trying to initialize a list in a class like this:
class Node():
def __init__(self):
self.info = None
self.word = ''
for i in range(256):
self.ptrs[0] = None
if __name__ == '__main__':
n = Node()
Now this throws an error
self.ptrs[0] = None
AttributeError: Node instance has no attribute 'ptrs'
I am sure that I'm missing something stupid. What is it?
Upvotes: 0
Views: 3797
Reputation: 64308
I think you want this:
class Node():
def __init__(self):
self.info = None
self.word = ''
self.ptrs = [None]*256
Upvotes: 3