module question
Bob van der Poel
bvdpoel at uniserve.com
Mon Jan 1 23:04:43 EST 2001
> >Now, to complicate my understanding even more...if I declare a variable
> >in the 'main' module or program how do I access it from imported modules?
> >For example, I might have something like:
> >
> > versionNumber = 1.4
> >
> >in the mainline. Now, a module (and I guess it might be deeply
> >nested), wants to find out what version is running. I just tried a
> >few variations of 'global', but nothing seems to work. Passing this
> >variable around to everyone who might need it gets real old, real
> >fast...so I'm thinking I'm not understanding something!
>
> Ordinarily I'd recommend against this, but this seems like it might be
> an appropriate use. In your edit module, do this:
>
> import __main__
> print __main__.versionNumber
Yes, just after I posted this note I realized (remembered) the thing
about __main__. But it is ugly!
> OTOH, that's such a horrid kludge that what you *really* should do is
> have a config module of some sort where you store the version number and
> import *that* into all your modules (including main).
Ahh, yes. Perfect. One of these days I'll start to think in Python
instead of assembler.
Thanks.
--
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at uniserve.com
WWW: http://users.uniserve.com/~bvdpoel
More information about the Python-list
mailing list