Globals

Jeff Layton jeffrey.b.layton at lmco.com
Fri Oct 18 06:41:16 EDT 2002


Newt wrote:

> Hi,
>
> What's the best 'way' of defining globals?

   How about a newbie answer? I've been using a 'Borg' to do
something like what you mentioned:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531

I created a 'Borg' class then in each module where I need
it, I can create an instance of the class there and access the
data and methods in the class. Very cool for my application
(thank you Alex!).

Good Luck!

Jeff



>
>
> To better express my self, if I wanted to have strVar (a string), iVar (an
> integer) (for example) as globals, I assume I'd have to declare them in my
> main program:
>
> strVar = ""
> iVar = 0
>
> and use the global command when ever I wanted to reference them:
>
> global strVar
> global iVar
>
> Questions:
>
> 1. Is this the correct/best way?
> 2. To save typing in all the global statements, can I put them in to an
> include file or a source file?
> 3. If I declare them in a .py file, do I still need the global commands to
> use them within Classes and Functions etc defined within that same module?
>
> Thanks
>
> Newt

--

Jeff Layton

"Is it possible to overclock a cattle prod?" - Irv Mullins

This email may contain confidential information. If you have received this
email in error, please delete it immediately, and inform me of the mistake by
return email. Any form of reproduction, or further dissemination of this
email is strictly prohibited. Also, please note that opinions expressed in
this email are those of the author, and are not necessarily those of the
Lockheed-Martin Corporation.






More information about the Python-list mailing list