Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16832

Initialize variable for whole python package

$
0
0

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?

I tried different things that only work partially.

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

I want to be able to do:

import my_packagemy_package.init(1234)my_package.subpackage.my_function() <---- Should be able to use x with its 1234 value

Viewing all articles
Browse latest Browse all 16832

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>