Re: Python 2.6 Global Variables

2009-10-30 Thread Aahz
In article <888b5e8f-1be5-4040-bc7a-45c2e1695...@d9g2000prh.googlegroups.com>, AK Eric wrote: >> >> 2/ in Python, "global" really means "module-level" - there's nothing >> like a "true" global namespace. > >Isn't that __main__? > >import __main__ >__main__.foo = "asdfasdf" > >print foo ># asdfasd

Re: Python 2.6 Global Variables

2009-10-30 Thread Stephen Hansen
On Fri, Oct 30, 2009 at 9:01 AM, AK Eric wrote: > Should we start talking about how you can add stuff to __builtin__ and > then it really is exposed to everything? (right, unless I'm missing > some other Python idiom?) Again, *not advocating* in standard > practice, but I think it's important to

Re: Python 2.6 Global Variables

2009-10-30 Thread AK Eric
> > It isn't a neat trick anymore once you realize the name '__main__' > > isn't special. > > > Replace __main__ with foo, or config, or whatever, and you get the > > same results. Ok, there is a catch: a file with that name must exist, > > at least an empty one... True. I do feel a bit less spec

Re: Python 2.6 Global Variables

2009-10-30 Thread Dave Angel
Gabriel Genellina wrote: En Fri, 30 Oct 2009 00:29:27 -0300, Steven D'Aprano escribió: On Thu, 29 Oct 2009 10:31:03 -0700, AK Eric wrote: 2/ in Python, "global" really means "module-level" - there's nothing like a "true" global namespace. It isn't a neat trick anymore once you realize the

Re: Python 2.6 Global Variables

2009-10-30 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : AK Eric a écrit : 2/ in Python, "global" really means "module-level" - there's nothing like a "true" global namespace. Isn't that __main__? Nope import __main__ __main__.foo = "asdfasdf" print foo # asdfasdf Not advocating, but it does serve the purpose.

Re: Python 2.6 Global Variables

2009-10-30 Thread Bruno Desthuilliers
AK Eric a écrit : 2/ in Python, "global" really means "module-level" - there's nothing like a "true" global namespace. Isn't that __main__? Nope import __main__ __main__.foo = "asdfasdf" print foo # asdfasdf Not advocating, but it does serve the purpose. This won't make 'foo' available

Re: Python 2.6 Global Variables

2009-10-29 Thread Gabriel Genellina
En Fri, 30 Oct 2009 00:29:27 -0300, Steven D'Aprano escribió: On Thu, 29 Oct 2009 10:31:03 -0700, AK Eric wrote: 2/ in Python, "global" really means "module-level" - there's nothing like a "true" global namespace. Isn't that __main__? Well there you go, I just learned something new. I w

Re: Python 2.6 Global Variables

2009-10-29 Thread Steven D'Aprano
On Thu, 29 Oct 2009 10:31:03 -0700, AK Eric wrote: >> 2/ in Python, "global" really means "module-level" - there's nothing >> like a "true" global namespace. > > Isn't that __main__? Well there you go, I just learned something new. I was going to say "No, every module has its own __main__", and

Re: Python 2.6 Global Variables

2009-10-29 Thread Benjamin Kaplan
On Thu, Oct 29, 2009 at 7:11 PM, AK Eric wrote: >> Good that you're not advocating it, because IMHO it's bad practice to >> have circular import dependencies.  By using the __main__ alias, you >> avoid the worst problems, but that just means the others are more subtle. > > I figured I'd get that k

Re: Python 2.6 Global Variables

2009-10-29 Thread AK Eric
> Good that you're not advocating it, because IMHO it's bad practice to > have circular import dependencies.  By using the __main__ alias, you > avoid the worst problems, but that just means the others are more subtle. I figured I'd get that kind of response, not that it's incorrect ;) Great power

Re: Python 2.6 Global Variables

2009-10-29 Thread Dave Angel
AK Eric wrote: 2/ in Python, "global" really means "module-level" - there's nothing like a "true" global namespace. Isn't that __main__? import __main__ __main__.foo = "asdfasdf" print foo # asdfasdf Not advocating, but it does serve the purpose. Good that you're not advocating it,

Re: Python 2.6 Global Variables

2009-10-29 Thread AK Eric
> 2/ in Python, "global" really means "module-level" - there's nothing > like a "true" global namespace. Isn't that __main__? import __main__ __main__.foo = "asdfasdf" print foo # asdfasdf Not advocating, but it does serve the purpose. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 2.6 Global Variables

2009-10-29 Thread Chris Rebert
On Thu, Oct 29, 2009 at 3:25 AM, VYAS ASHISH M-NTB837 wrote: > > Dear all > > How do I write a code that gets executed 'every x' minutes? > > > > I know how to do it 'after x' minutes, I do the following: > > def doAtTimerFire(): >        """ The things I want to do 'after x' minutes go here. """

RE: Python 2.6 Global Variables

2009-10-29 Thread VYAS ASHISH M-NTB837
Dear all How do I write a code that gets executed 'every x' minutes? I know how to do it 'after x' minutes, I do the following: def doAtTimerFire(): """ The things I want to do 'after x' minutes go here. """ And then from main code, I do this: tmr = threading.Timer(timeInSeconds,

Re: Python 2.6 Global Variables

2009-10-29 Thread Bruno Desthuilliers
Ronn Ross a écrit : (please don't top-post - fixed) On Oct 28, 2009, at 20:50, mattofak wrote: Hi All; I'm new to Python and moving from C, which is probably a big source of my confusion. I'm struggling with something right now though and I hope you all can help. I have a global configuratio

Re: Python 2.6 Global Variables

2009-10-28 Thread Benjamin Kaplan
On Wed, Oct 28, 2009 at 8:50 PM, mattofak wrote: > Hi All; > > I'm new to Python and moving from C, which is probably a big source of > my confusion. I'm struggling with something right now though and I > hope you all can help. > > I have a global configuration that I would like all my classes and

Re: Python 2.6 Global Variables

2009-10-28 Thread Chris Rebert
> On Oct 28, 2009, at 20:50, mattofak wrote: >> Hi All; >> >> I'm new to Python and moving from C, which is probably a big source of >> my confusion. I'm struggling with something right now though and I >> hope you all can help. >> >> I have a global configuration that I would like all my classes

Re: Python 2.6 Global Variables

2009-10-28 Thread Ronn Ross
Inside the method that you want to use the var prefix the first instance with global. For example: global my_var. Then you can use the var like normal in the method. Good luck On Oct 28, 2009, at 20:50, mattofak wrote: Hi All; I'm new to Python and moving from C, which is probably a big