0

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?

1 Answer 1

3

I think you want this:

class Node():
    def __init__(self):
        self.info = None
        self.word = ''
        self.ptrs = [None]*256
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.