Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

JavaScriptDude/app_global

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

1 Commit

Repository files navigation

app_global

From docs.python.org:

"The canonical way to share information across modules within a single program is to create a special module (often called config or cfg). Just import the config module in all modules of your application; the module then becomes available as a global name. Because there is only one instance of each module, any changes made to the module object get reflected everywhere. For example:"


See /Example/app_global_test for an illustration that can be run in VSCode


Although not illustrated, it is recommended to categorize data within the app globals to keep organized and thus reduce possiblity obscure failure:

  • config.C - For global constants
  • config.G - For global application state like DB connections, caches etc.
  • config.opts - Application options
  • config.log - Application logger
  • config.printCli - Common print cli handler for clean exit during initialization

As with any global data, care should be taken when using from within any multi threading applications. Use appropriate locking mechanisms as required.


Besides improving documentation, the main source config.py will be left as an empty source file so that is infinitely flexible

About

Sharing global variables between modules in a Python application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /