Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Is there a way to define a true global across modules?

Reply
Thread Tools

Re: Is there a way to define a true global across modules?

 
 
Fredrik Lundh
Guest
Posts: n/a
 
      11-03-2006
Hendrik van Rooyen wrote:

> I am struggling with this - I want to define a "system-wide" flag for use as a
> semaphore.


http://www.effbot.org/pyfaq/how-do-i...ss-modules.htm

</F>

 
Reply With Quote
 
 
 
 
robert
Guest
Posts: n/a
 
      11-03-2006
Fredrik Lundh wrote:
> Hendrik van Rooyen wrote:
>
>> I am struggling with this - I want to define a "system-wide" flag for
>> use as a
>> semaphore.

>
> http://www.effbot.org/pyfaq/how-do-i...ss-modules.htm
>


Or worse style - if you are too lazy to create a extra global variables module (ab)use the __main__ module als "global":


import __main__

__main__.mysemphore += 1



-robert
 
Reply With Quote
 
 
 
 
Hendrik van Rooyen
Guest
Posts: n/a
 
      11-04-2006
"robert" <no-> wrote:


> Fredrik Lundh wrote:
> > Hendrik van Rooyen wrote:
> >
> >> I am struggling with this - I want to define a "system-wide" flag for
> >> use as a
> >> semaphore.

> >
> >

http://www.effbot.org/pyfaq/how-do-i...ss-modules.htm
> >

>
> Or worse style - if you are too lazy to create a extra global variables module

(ab)use the __main__ module als "global":
>
>
> import __main__
>
> __main__.mysemphore += 1
>
>
> -robert


Thanks - how could you possibly have guessed that I am lazy - does it show that
much? *WEG*

- Hendrik

 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      11-06-2006
Hendrik van Rooyen wrote:
> "robert" <no-> wrote:
> > Fredrik Lundh wrote:
> > > http://www.effbot.org/pyfaq/how-do-i...ss-modules.htm


> > Or worse style - if you are too lazy to create a extra global variables module
> > (ab)use the __main__ module als "global":
> > import __main__
> > __main__.mysemphore += 1


> Thanks - how could you possibly have guessed that I am lazy - does it show that
> much? *WEG*


You could merge the two approaches and bind a more explicit name to
__main__:

import __main__ as config

config.mysemaphore = 0

It's a little clearer what you're subverting __main__ for here

- alex23

 
Reply With Quote
 
Hendrik van Rooyen
Guest
Posts: n/a
 
      11-06-2006
"alex23" <> wrote:

> Hendrik van Rooyen wrote:
> > "robert" <no-> wrote:
> > > Fredrik Lundh wrote:
> > > >

http://www.effbot.org/pyfaq/how-do-i...ss-modules.htm
>
> > > Or worse style - if you are too lazy to create a extra global variables

module
> > > (ab)use the __main__ module als "global":
> > > import __main__
> > > __main__.mysemphore += 1

>
> > Thanks - how could you possibly have guessed that I am lazy - does it show

that
> > much? *WEG*

>
> You could merge the two approaches and bind a more explicit name to
> __main__:
>
> import __main__ as config
>
> config.mysemaphore = 0
>
> It's a little clearer what you're subverting __main__ for here
>
> - alex23


Thanks - clever and clear!

- Hendrik

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[False,True] and [True,True] --> [True, True]????? bdb112 Python 45 04-29-2009 02:35 AM
Is there a way to define a true global across modules? Hendrik van Rooyen Python 0 11-03-2006 03:37 PM
global typedefs and #define /\ global inheritance base eiji C++ 5 12-06-2005 12:19 AM
newbiw question: What is the best way to declare and define global variables? david C Programming 1 10-06-2004 04:04 PM
What's the best way to define global variable David WOO C++ 12 03-05-2004 04:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57