Most of the times I encounter this problem I use different methods:
- I put all constants that are to be used in all programs in a separate program that can be imported.
- I create a "shared variables object" for variables that are to be used in several modules. This object is passed to the constructor of a class. The variables can then be accessed (and modified) in the class that is using them.
So when the program starts this class is instantiated and after that passed to the different modules. This also makes it flexible in that when you add an extra field to the class, no parameters need to be changed.
class session_info:
def __init__(self, shared_field1=None, shared_field2=None ....):
self.shared_field1 = shared_field1
self.shared_field2 = shared_field2
def function1(session):
session.shared_field1 = 'stilton'
def function2(session):
print('%s is very runny sir' % session.shared_field1)
session = session_info()
function1(session)
function2(session)
Should print:
"stilton is very runny sir"