1

I have this code:

class A():
    def __init__(self):
        self.new_list = ['one', 'two', 'three']


class B():
    a = A()
    def foo():
        print(a.new_list)

When I type

b = B()
b.foo()

I get this error:

NameError: name 'a' is not defined 

I don't understand why because I already created the object a with the A() class

  • Please update your question with your actual code. I get a different error to the one claimed. – quamrana Feb 15 '22 at 14:53
  • Does this answer your question? [How can I access "static" class variables within methods in Python?](https://stackoverflow.com/questions/707380/how-can-i-access-static-class-variables-within-methods-in-python) – mkrieger1 Feb 15 '22 at 14:54

0 Answers0