I know I'm being dense and I know what the problem is but I can't seem to figure out how to fix it.
testcode.py
import t2
class t1:
saved = 0
@classmethod
def set_class(cls, number):
t1.saved = number
not_in_main = t1
if __name__ == "__main__":
not_in_main.set_class(6)
used_everywhere = t1
used_everywhere.set_class(4)
t2.f1()
and then in t2.py
import testcode
def f1():
print(f'not_in_main: {testcode.not_in_main.saved}')
print(f'got here: {testcode.used_everywhere.saved}')
Now the output after running python testcode.py
will be
not_in_main: 0
AttributeError: module 'testcode' has no attribute 'used_everywhere'
So not_in_main has two different instances one in the main scope and one module scope. Used_everywhere is also in the main scope but another module can't see in instance.
I've looked at many of the scoping issues but I don't see how to fix this. What am I doing wrong?