The best way to share global variables across modules across a single program is to create a config module. Just import the config module in all modules of your application; the module then becomes available as a global name.
To share global variables across modules within a single program, create a special module. Import the config module in all modules of your application. The module will be available as a global variable across modules.
There is no such way to pass parameters to the module, however you can revamp your code a bit and import the parameters from a module as global parameters.
I'm wonder why this simple code doesn't work.
In main.py I have
def foo():
HTTPHelper.setHost("foo")
host = HTTPHelper.host()
and in HTTPHelper.py:
_host = None
def setHost(host):
_host = host
def host():
return _host
But when I step through foo() host becomes NoneType, even though I set it on the line before. Very confused...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With