I have this situation:
library_file1.py:
class A:
def foo(self):
print("bar")
def baz(self):
pass
project_file.py:
from library_file1 import A
class B(A):
def baz(self):
print(the_variable)
library_file2.py:
from project_file import B
the_variable = 7
b = B()
b.foo() # prints "bar"
b.baz() # I want this to print "7", but I don't know how
How do I allow code to be written in project_file.py
that can access variables from library_file2.py? The only solution I can think of is this:
project_file.py:
from library_file1 import A
class B(A):
def baz(self, the_variable):
print(the_variable)
library_file2.py:
from project_file import B
the_variable = 7
b = B()
b.foo()
b.baz(the_variable)
but this feels awkward and doesn't scale to many variables like the_variable
.