Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables between modules [duplicate]

Tags:

People also ask

How do you pass variables between modules?

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.

How do I share global variables across modules?

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.

How do you pass parameters to a Python module?

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...