spir # wrote:
On Sun, 28 Mar 2010 21:50:46 +1100
Steven D'Aprano <st...@pearwood.info> wrote:

On Sun, 28 Mar 2010 08:31:57 pm spir ☣ wrote:
<snip>
I'm going to assume you really want a single global value, and that you won't regret that assumption later.

We talked at length about how to access that global from everywhere that cares, and my favorite way is with a globals module. And it should be assigned something like:

globals.py:
class SomeClass (object):
def....

def init(parameters):
global world
world = SomeClass(parameters, moreparamaters)

Then main can do the following:
import globals
globals.init(argv-stuff)

And other modules can then do
import globals.world as world

And they'll all see the same world variable. Nobody should have their own, but just import it if needed.


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to