python global parameters file -


I have a python script that calls many functions from other scripts. I give the script as a parameter in the form of a setting file as this:

  var1 = XXX var2 = YYY ...  
< P> I would like to make those variables global so that I can use them in every celebration but without having them clear clearly, what is the best way to do this?

Thank you.

The simplest way the module (such as settings.py ) Recommended.

You define the variables in the module only and they will be available for any module that is settings.var_name via the settings module.

Example:

File settings.py :

  var_name = "value"  

File m.py :

  #! A preferred method is to use the environment (the hair process handles the environment) to pass it in a global context. You can use it for this purpose.  

An example of how to do this:

File a.py :

    

File b.py / code> :

  import os def echo (): print os.environ ['var_name']  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -