Editing My Python Coding Conventions

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 82: Line 82:
  
 
=== Global Variables and Application State ===
 
=== Global Variables and Application State ===
Globals are often disparaged, in part because of strong coupling between components. Nevertheless they are very useful in applications. My approach is to use a class, never instantiated which is a singleton and which holds the global variables. This is in a file called app_global.py, check out the ( very simple ) code there.  Objects that need to be globally available typically have an __init__
+
Globals are often.....
which contains a line much like  AppGlobal.a_global_reference = self.  It can then be accessed anywhere in the code ( after from app_global import AppGlobal ) as: a_useful_ref  = AppGlobal.a_global_reference.  Other application state information may be shared in an object of the class AppState.  Not quite sure how these differ form AppGlobals, maybe they doe not ( although I usually use an instance of this not the class itself ).  All this works fine, so I am using it this way now, but I need to think more about the proper way to code this stuff.
 
  
 
=== MultiThreading ===
 
=== MultiThreading ===

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)