I built a package that contains different modules. Everything works, but i have a problem initializing a variable. In the package,i need an init() function to initialize a variable. How can i make this variable available in all my modules/functions?
我尝试了只有部分工作的不同情况。
my_package
__init__.py
init()
subpackage
my_function <---- How to use x?
**__init.py__**
global x
def init(initial_value):
global x
x=initial_value
我想做到:
import my_package
my_package.init(1234)
my_package.subpackage.my_function() <---- Should be able to use x with its 1234 value