Say I have class Test defined as this:
class Test
test_var = 2
def test_func():
print(test_var)
I can find out what test_var is fine like so:
>>> Test.test_var
2
...But calling Test.test_func() does not work.
>>> Test.test_func()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in test
NameError: name 'test_var' is not defined
If I change Test.test_func() like this (note that this is pseudo-code):
redef test_func():
print(Test.test_var)
It works fine:
>>> Test.test_func()
2
...and that makes sense. But how can I make the first example work, keeping in mind that I want test_func to be an instance method?
Note that the code posted above is example code, and so typos should be ignored.
test_funcis not a class method or instance method so it doesn't know about the class namespace.test_funcnot a class method?