Re: Global variables for python applications

2010-05-20 Thread TomF
On 2010-05-19 07:34:37 -0700, Steven D'Aprano said: # Untested. def verbose_print(arg, level, verbosity=1): if level <= verbosity: print arg def my_function(arg): my_print(arg, level=2) return arg.upper() if __name__ == '__main__': if '--verbose' in sys.argv:

Re: Global variables for python applications

2010-05-19 Thread Steven D'Aprano
On Wed, 19 May 2010 00:16:56 -0700, TomF wrote: > Let's say you have a bunch of globals, one of which is a verbose flag. > If I understand the difference, using a module gbls.py: > > # in gbls.py > verbose = False > # elsewhere: > import gbls > gbls.verbose = True > > Using a class: > > # In th

Re: Global variables for python applications

2010-05-19 Thread TomF
On 2010-05-16 12:27:21 -0700, christian schulze said: On 16 Mai, 20:20, James Mills wrote: On Mon, May 17, 2010 at 4:00 AM, Krister Svanlund wrote: On Sun, May 16, 2010 at 7:50 PM, AON LAZIO wrote:    How can I set up global variables for the entire python applications? Like I can call an

Re: Global variables for python applications

2010-05-18 Thread Duncan Booth
Steven D'Aprano wrote: > I think it is an abuse of the term constant to allow you to talk about a > mutable object being "constant", since it can vary. Generally, you don't > care about identity, only equality. Making up a syntax on the spot: > > constant pi = [3.1415] > assert pi = 3.1415 > p

Re: Global variables for python applications

2010-05-17 Thread Steven D'Aprano
On Mon, 17 May 2010 23:54:38 +0100, Rhodri James wrote: > On Mon, 17 May 2010 05:29:20 +0100, Steven D'Aprano > wrote: > >> On Sun, 16 May 2010 18:57:15 -0700, John Nagle wrote: >> >>> James Mills wrote: The only place global variables are considered somewhat "acceptable" are as consta

Re: Global variables for python applications

2010-05-17 Thread Giampaolo Rodolà
2010/5/16 Chris Rebert : > On Sun, May 16, 2010 at 10:50 AM, AON LAZIO wrote: >> Hi, >>How can I set up global variables for the entire python applications? >> Like I can call and set this variables in any .py files. >>Think of it as a global variable in a single .py file but this is for t

Re: Global variables for python applications

2010-05-17 Thread Rhodri James
On Mon, 17 May 2010 05:29:20 +0100, Steven D'Aprano wrote: On Sun, 16 May 2010 18:57:15 -0700, John Nagle wrote: James Mills wrote: The only place global variables are considered somewhat "acceptable" are as constants in a module shared as a static value. Python really ought to have

Re: Global variables for python applications

2010-05-17 Thread Steven D'Aprano
On Mon, 17 May 2010 19:56:15 +1200, Gregory Ewing wrote: > John Nagle wrote: >> Also, more compile-time arithmetic becomes possible. > > But only if their values can be computed at compile time. John said "more", not "everything imaginable can be calculated at compile time" :) Python already d

Re: Global variables for python applications

2010-05-17 Thread Gregory Ewing
John Nagle wrote: Also, more compile-time arithmetic becomes possible. But only if their values can be computed at compile time. This leads to a huge can of worms if you want to be able to import named constants from other modules. A large part of what currently happens only at run time would h

Re: Global variables for python applications

2010-05-16 Thread James Mills
On Mon, May 17, 2010 at 2:24 PM, Steven D'Aprano wrote: > In what way are they constant? Can you not modify them and rebind them? It's just style/convention :) Much like _ to denote private variables and methods! --james -- http://mail.python.org/mailman/listinfo/python-list

Re: Global variables for python applications

2010-05-16 Thread Steven D'Aprano
On Sun, 16 May 2010 18:57:15 -0700, John Nagle wrote: > James Mills wrote: >> The only place global variables are considered somewhat "acceptable" >> are as constants in a module shared as a static value. > > Python really ought to have named constants. +1 Unfortunately, it will most likely

Re: Global variables for python applications

2010-05-16 Thread Steven D'Aprano
On Mon, 17 May 2010 13:34:57 +1000, James Mills wrote: > On Mon, May 17, 2010 at 11:57 AM, John Nagle wrote: >>   For one thing, it's fine to share constants across threads, while >> sharing globals is generally undesirable.  Also, more compile-time >> arithmetic becomes possible. >> >>   Python

Re: Global variables for python applications

2010-05-16 Thread James Mills
On Mon, May 17, 2010 at 11:57 AM, John Nagle wrote: >   For one thing, it's fine to share constants across threads, while > sharing globals is generally undesirable.  Also, more compile-time > arithmetic becomes possible. > >   Python does have a few built-in named unassignable constants: > "True"

Re: Global variables for python applications

2010-05-16 Thread John Nagle
James Mills wrote: The only place global variables are considered somewhat "acceptable" are as constants in a module shared as a static value. Python really ought to have named constants. For one thing, it's fine to share constants across threads, while sharing globals is generally undes

Re: Global variables for python applications

2010-05-16 Thread christian schulze
On 16 Mai, 20:20, James Mills wrote: > On Mon, May 17, 2010 at 4:00 AM, Krister Svanlund > > wrote: > > On Sun, May 16, 2010 at 7:50 PM, AON LAZIO wrote: > >>    How can I set up global variables for the entire python applications? > >> Like I can call and set this variables in any .py files. >

Re: Global variables for python applications

2010-05-16 Thread James Mills
On Mon, May 17, 2010 at 4:00 AM, Krister Svanlund wrote: > On Sun, May 16, 2010 at 7:50 PM, AON LAZIO wrote: >>    How can I set up global variables for the entire python applications? >> Like I can call and set this variables in any .py files. >>    Think of it as a global variable in a single .

Re: Global variables for python applications

2010-05-16 Thread Chris Rebert
On Sun, May 16, 2010 at 10:50 AM, AON LAZIO wrote: > Hi, >    How can I set up global variables for the entire python applications? > Like I can call and set this variables in any .py files. >    Think of it as a global variable in a single .py file but this is for the > entire application. Thank

Re: Global variables for python applications

2010-05-16 Thread Krister Svanlund
On Sun, May 16, 2010 at 7:50 PM, AON LAZIO wrote: > Hi, >    How can I set up global variables for the entire python applications? > Like I can call and set this variables in any .py files. >    Think of it as a global variable in a single .py file but this is for the > entire application. >    Th

Re: Global variables for python applications

2010-05-16 Thread James Mills
On Mon, May 17, 2010 at 3:50 AM, AON LAZIO wrote: > Hi, >    How can I set up global variables for the entire python applications? > Like I can call and set this variables in any .py files. >    Think of it as a global variable in a single .py file but this is for the > entire application. If you

Global variables for python applications

2010-05-16 Thread AON LAZIO
Hi, How can I set up global variables for the entire python applications? Like I can call and set this variables in any .py files. Think of it as a global variable in a single .py file but this is for the entire application. Thanks -- Aonlazio 'Peace is always the way.' NW -- http://mai