Re: Global variables problem

2010-08-04 Thread Jean-Michel Pichavant
Navkirat Singh wrote: On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote: Please post approximate code that actually works and displays the problem. On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh > wrote: Hey guys, I am using a multiprocessing program, w

Re: Global variables problem

2010-08-04 Thread Matteo Landi
Usually, modify global variables in a multi-thread/multi-process scenario is not the right to operate: you better re-implement your solution in a way that the shared resource is either protected with synchronized objects or accessed by a single thread/process (and in this case, it won't be a share

Re: Global variables problem

2010-08-04 Thread Navkirat Singh
: ( False alarm, the earlier solution breaks multiprocessing. Whats happening here is the child needs to change a variable in the parent process, So I think I am looking at shared memory (maybe). Any suggestions? Regards, Nav On 04-Aug-2010, at 12:41 PM, Navkirat Singh wrote: > Thanks a l

Re: Global variables problem

2010-08-04 Thread Navkirat Singh
Thanks a lot guys !! I solved the problem: In the lines: >> new_process = process(target=newprocess) >>new_process.start() The target=newprocess is pointing towards a variable, instead of a function. So, appending a () will make it goto that function, thereby changing

Re: Global variables problem

2010-08-03 Thread Daniel da Silva
Your problem lies somewhere in the use of the Process class, not with global variables. If you replace your "p = ..." and "p.start()" lines with a direct call to self.handle_connection(), your code works as expected. I don't know much about the multiprocessing module, so I can't really comment on

Re: Global variables problem

2010-08-03 Thread Navkirat Singh
On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote: > Please post approximate code that actually works and displays the problem. > > On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh wrote: > Hey guys, > > I am using a multiprocessing program, where the new process is supposed to > change a vari

Re: Global variables problem

2010-08-03 Thread Daniel da Silva
Please post approximate code that actually works and displays the problem. On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh wrote: > Hey guys, > > I am using a multiprocessing program, where the new process is supposed to > change a variable in the main class that it branches out from. This is > s

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 in imported modules

2010-05-16 Thread vsoler
On 17 mayo, 00:52, Patrick Maupin wrote: > On May 16, 5:38 pm, James Mills wrote: > > > On Mon, May 17, 2010 at 8:26 AM, vsoler wrote: > > > However, can I be 100% sure that,no matter how I access variable > > > 'x' (with config.x or mod.config.x) it is always the same 'x'. I mean > > > that eit

Re: global variables in imported modules

2010-05-16 Thread Patrick Maupin
On May 16, 5:38 pm, James Mills wrote: > On Mon, May 17, 2010 at 8:26 AM, vsoler wrote: > > However, can I be 100% sure that,no matter how I access variable > > 'x' (with config.x or mod.config.x) it is always the same 'x'. I mean > > that either reference of 'x' points to the same id(memory posi

Re: global variables in imported modules

2010-05-16 Thread vsoler
On 17 mayo, 00:38, James Mills wrote: > On Mon, May 17, 2010 at 8:26 AM, vsoler wrote: > > However, can I be 100% sure that,no matter how I access variable > > 'x' (with config.x or mod.config.x) it is always the same 'x'. I mean > > that either reference of 'x' points to the same id(memory posit

Re: global variables in imported modules

2010-05-16 Thread James Mills
On Mon, May 17, 2010 at 8:26 AM, vsoler wrote: > However, can I be 100% sure that,no matter how I access variable > 'x' (with config.x or mod.config.x) it is always the same 'x'. I mean > that either reference of 'x' points to the same id(memory position)? Yes it does unless you re-assign it. --

Re: global variables in imported modules

2010-05-16 Thread vsoler
On 17 mayo, 00:05, Patrick Maupin wrote: > On May 16, 4:42 pm, vsoler wrote: > > > > > Taken fromwww.python.org, FAQ 2.3 How do I share global variables > > across modules? > > > config.py: > > > x = 0   # Default value of the 'x' configuration setting > > > mod.py: > > > import config > > config

Re: global variables in imported modules

2010-05-16 Thread Rhodri James
On Sun, 16 May 2010 22:42:40 +0100, vsoler wrote: Taken from www.python.org, FAQ 2.3 How do I share global variables across modules? config.py: x = 0 # Default value of the 'x' configuration setting mod.py: import config config.x = 1 main.py: import config # try removing it impo

Re: global variables in imported modules

2010-05-16 Thread Patrick Maupin
On May 16, 4:42 pm, vsoler wrote: > Taken fromwww.python.org, FAQ 2.3 How do I share global variables > across modules? > > config.py: > > x = 0   # Default value of the 'x' configuration setting > > mod.py: > > import config > config.x = 1 > > main.py: > > import config       # try removing it >

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

Re: Global variables from a class

2009-05-29 Thread Javier Collado
You're right. I agree on that it's important to use proper words. Thanks for the correction. Best regards, Javier 2009/5/29 Steven D'Aprano : > On Fri, 29 May 2009 12:04:53 +0200, Javier Collado wrote: > >> Hello, >> >> First thing is a class variable (one for every instance) and second one >

Re: Global variables from a class

2009-05-29 Thread Dave Angel
Kless wrote: I usually use a class to access to global variables. So, which would be the correct way to set them --since the following classes--: class Foo: var = 'lala' class Bar: def __init__(self): self.var = 'lele' Or is it the same?

Re: Global variables from a class

2009-05-29 Thread Jean-Michel Pichavant
Kless wrote: I usually use a class to access to global variables. So, which would be the correct way to set them --since the following classes--: class Foo: var = 'lala' class Bar: def __init__(self): self.var = 'lele' Or is it the same?

Re: Global variables from a class

2009-05-29 Thread Steven D'Aprano
On Fri, 29 May 2009 12:04:53 +0200, Javier Collado wrote: > Hello, > > First thing is a class variable (one for every instance) and second one > an instance variable (one per instance). One of these things don't belong: A string variable is a variable holding a string. A float variable is a var

Re: Global variables from a class

2009-05-29 Thread Javier Collado
Hello, First thing is a class variable (one for every instance) and second one an instance variable (one per instance). For further information, please take a look at: http://diveintopython.org/object_oriented_framework/class_attributes.html Best regards, Javier 2009/5/29 Kless : > I usually

Re: Global variables from a class

2009-05-29 Thread Piet van Oostrum
> Kless (K) wrote: >K> I usually use a class to access to global variables. So, which would >K> be the correct way to set them --since the following classes--: >K> >K> class Foo: >K>var = 'lala' >K> class Bar: >K>def __init__(self): >K> self.var = 'lele' >

Re: Global variables in modules...

2008-03-28 Thread Terry Jones
> "Peter" == Peter Otten <[EMAIL PROTECTED]> writes: Peter> [EMAIL PROTECTED] wrote: [snip] >> ...can someone explain why invoking a.py prints 0? >> I would have thought that the global variable 'g' of module 'a' would >> be set to 1... Peter> When you run a.py as a script it is put into the s

Re: Global variables in modules...

2008-03-28 Thread ttsiodras
That clears it up. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Global variables in modules...

2008-03-28 Thread Peter Otten
[EMAIL PROTECTED] wrote: > With a.py containing this: > > == a.py === > #!/usr/bin/env python > import b > > g = 0 > > def main(): > global g > g = 1 > b.callb() > > if __name__ == "__main__": > main() > == > > ...and b.py containing...

Re: global variables: to be or not to be

2008-02-22 Thread John Henry
On Feb 22, 9:20 pm, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Fri, 22 Feb 2008 19:11:01 -0800 (PST), icarus <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > > But how do I get around it? How do I update and access a variable > > anytime I want? Any easy-to-follow e

Re: global variables: to be or not to be

2008-02-22 Thread subeen
Another way to avoid using global variables is to return more than one values from the function. Here is an example that may help you to understand it: def foo(a, b, c): a += c b += c return a, b a = 5 b = 10 c = 2 print a, b a, b = foo(a, b, c) print a, b regards, Subeen. http://l

Re: global variables: to be or not to be

2008-02-22 Thread Matt Nordhoff
icarus wrote: > I've read 'global variables' are bad. The ones that are defined as > 'global' inside a function/method. > > The argument that pops up every now and then is that they are hard to > keep track of. I don't know Python well enough to argue with that. > Just started learning it a few

Re: Global variables within classes.

2007-11-30 Thread Bruno Desthuilliers
Kevac Marko a écrit : > On Nov 10, 8:39 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> Don't think so. It's a surprise for many but then class attributes are >> not that common in code or they even use this "gotcha" for >> immutable default values. As long a the value isn't changed th

Re: Global variables within classes.

2007-11-30 Thread Bruno Desthuilliers
Donn Ingle a écrit : (about class attributes, instance attributes and lookup rules) > Okay, I sort of see that. It's not a property For clarity, better s/property/attribute/ here. In Python, property is a builtin class used for computed attributes. > of 'j' so it looks upwards > into the class.

Re: Global variables within classes.

2007-11-30 Thread MarkE
> Kevac Marko <[EMAIL PROTECTED]> writes: > > When changing default value, is there any way to change class > > attribute and all referenced attributes too? > > > class M: > > name = u"Marko" > > > a, b = M(), M() > > a.name = u"Kevac" > > print M.name, a.name, b.name > > -> Marko Kevac Marko >

Re: Global variables within classes.

2007-11-27 Thread Hrvoje Niksic
Kevac Marko <[EMAIL PROTECTED]> writes: > When changing default value, is there any way to change class > attribute and all referenced attributes too? > > class M: > name = u"Marko" > > a, b = M(), M() > a.name = u"Kevac" > print M.name, a.name, b.name > -> Marko Kevac Marko > > Is there any w

Re: Global variables within classes.

2007-11-27 Thread Kevac Marko
On Nov 10, 8:39 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > Don't think so. It's a surprise for many but then class attributes are > not that common in code or they even use this "gotcha" for > immutable default values. As long a the value isn't changed the default > value is just

Re: Global variables within classes.

2007-11-16 Thread Donn Ingle
Very interesting reply. I must ask a few questions, interleaved: > If you mean that all instances of Class Canvas and Thing will share > the *same* Stack, I think we can do it kind of like this: What's the difference between "same Stack" and "same instance of Stack"? I thought I knew what an insta

Re: Global variables within classes.

2007-11-14 Thread Bruno Desthuilliers
Donn Ingle a écrit : (snip) > I have been hearing about "new classes" for a while but there's no clarity > in the Python docs (that I can find). Then you perhaps should have a closer look at the entries in the 'documentation' sub-menu of python.org !-) Anyway, here's a direct link: http://python

Re: Global variables within classes.

2007-11-11 Thread uestc_mahui
On 11 10 , 10 01 , Donn Ingle <[EMAIL PROTECTED]> wrote: > > > def pop(self): > > item = self.list[-1] > > del self.list[-1] > > return item > > Is there some reason you do all that and not a self.list.pop(0)? > Hi. There are no special reasons I do it that way. Just

Re: Global variables within classes.

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 17:39:04 +, Marc 'BlackJack' Rintsch wrote: > On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote: print b.ref.attribute # print "haschanged" print j.ref.attribute #prints "original value" ## If it changed and an attribute of the Class, then ## wh

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Thanks for your time and patience Marc, that was some hotshot ascii art. I'll have to take some time to digest this. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: Global variables within classes.

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote: > Included again for clarity: >>> class Test: >>> attribute = "original value" >>> >>> class Bob: >>> def __init__(self): >>> self.ref = Test() >>> >>> class Jim: >>> def __init__(self): >>> self.ref =

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Included again for clarity: >> class Test: >> attribute = "original value" >> >> class Bob: >> def __init__(self): >> self.ref = Test() >> >> class Jim: >> def __init__(self): >> self.ref = Test() >> >> b = Bob() >> j = Jim() >> >> print b.ref.att

Re: Global variables within classes.

2007-11-10 Thread Marc 'BlackJack' Rintsch
On Sat, 10 Nov 2007 17:00:13 +0200, Donn Ingle wrote: >> The first creates an attribute of the class, the second creates an >> attribute in the instance. > > Given that, can you clarify this: > > class Test: > attribute = "original value" > > class Bob: > def __init__(self): >

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
> The first creates an attribute of the class, the second creates an > attribute in the instance. Given that, can you clarify this: class Test: attribute = "original value" class Bob: def __init__(self): self.ref = Test() class Jim: def __init__(self): se

Re: Global variables within classes.

2007-11-10 Thread Duncan Booth
Donn Ingle <[EMAIL PROTECTED]> wrote: >> class Stack: >> list = [] > Okay, this has me a little weirded-out. How is this different from > putting it in: > def __init__(self): > self.list = [] > ? > I see from tests that it is different, but I don't quite grok it. Who > owns the list r

Re: Global variables within classes.

2007-11-10 Thread Donn Ingle
Very interesting reply. I must ask a few questions, interleaved: > If you mean that all instances of Class Canvas and Thing will share > the *same* Stack, I think we can do it kind of like this: What's the difference between "same Stack" and "same instance of Stack"? I thought I knew what an insta

Re: Global variables within classes.

2007-11-10 Thread uestc_mahui
On 11 10 , 5 48 , Donn Ingle <[EMAIL PROTECTED]> wrote: > ## == API in another module perhaps === > Class Stack: > def push(self,stuff): > pass > > Class Canvas: > def do(self): > s.push("data") #I don't feel right about 's' here. > > Class Thing: > def buzz(self): > print s.pop(0) > >

Re: Global variables within classes.

2007-11-09 Thread Donn Ingle
> I guess you mean "instances", not "classes". Yes. > Err...Perhaps a dumb question, but what about passing the "common > objects" to initializers ? > s = Stack() > c = Canvas(s) > t = Thing(s) Okay, I see where you're going. It's better than what I have at the moment. Thanks. \d -- http://m

Re: Global variables within classes.

2007-11-09 Thread Bruno Desthuilliers
Donn Ingle a écrit : >>>I thought this might be a case for multiple inheritance >> >>??? > > Well, in terms of having Canvas and Thing inherit from Stack and thereby > (somehow, not sure how) they would both have access to Stack.stack (a list) > > >>wrt/ all Thing instances having to refer to a

Re: Global variables within classes.

2007-11-09 Thread Donn Ingle
>> I thought this might be a case for multiple inheritance > ??? Well, in terms of having Canvas and Thing inherit from Stack and thereby (somehow, not sure how) they would both have access to Stack.stack (a list) > wrt/ all Thing instances having to refer to a same Stack instance, > there's a pr

Re: Global variables within classes.

2007-11-09 Thread Bruno Desthuilliers
Donn Ingle a écrit : > Hi, > I'm getting myself really confused. I have three classes. Two of them need > to reference the third, like so: > > Canvas ---> Stack <--- Thing > > I am doing this right now: > > s = Stack() > > And then within I am referring directly to the global > variable 's' (a

Re: global variables

2007-10-02 Thread Bruno Desthuilliers
Colin J. Williams a écrit : > TheFlyingDutchman wrote: >> Does anyone know how the variables label and scale are recognized >> without a global statement or parameter, in the function resize() in >> this code: >> >> >> >> #!/usr/bin/env python >> >> from Tkinter import * >> >> def resize(ev=None):

Re: global variables

2007-10-02 Thread Colin J. Williams
TheFlyingDutchman wrote: > Does anyone know how the variables label and scale are recognized > without a global statement or parameter, in the function resize() in > this code: > > > > #!/usr/bin/env python > > from Tkinter import * > > def resize(ev=None): > label.config(font='Helvetica

Re: global variables

2007-10-02 Thread Erik Jones
On Oct 2, 2007, at 5:20 PM, TheFlyingDutchman wrote: > Does anyone know how the variables label and scale are recognized > without a global statement or parameter, in the function resize() in > this code: > > > > #!/usr/bin/env python > > from Tkinter import * > > def resize(ev=None): > lab

Re: global variables

2007-10-02 Thread Steven Bethard
TheFlyingDutchman wrote: > Does anyone know how the variables label and scale are recognized > without a global statement or parameter, in the function resize() in > this code: [snip] > def resize(ev=None): > label.config(font='Helvetica -%d bold' % \ > scale.get()) You're just cal

Re: global variables

2007-10-02 Thread Carsten Haese
On Tue, 2007-10-02 at 15:20 -0700, TheFlyingDutchman wrote: > Does anyone know how the variables label and scale are recognized > without a global statement or parameter, in the function resize() in > this code: > [...] The answer to your question is "Yes." -- Carsten Haese http://informixdb.sou

Re: Global variables, Classes, inheritance

2006-02-06 Thread DaveM
Thanks very much for the help to all who replied. I'd completely missed the difference between: class Foo: i = 12345 a = Foo() b = Foo() a.i = 678 and Foo.i = 678 Yeah, I know... DaveM -- http://mail.python.org/mailman/listinfo/python-list

Re: Global variables, Classes, inheritance

2006-02-03 Thread Kirk McDonald
DaveM wrote: > Although I've programmed for fun - on and off - since the mid 70's, I'm > definitely an OO (and specifically Python) beginner. > > My first question is about global variables. Are they, as I'm starting to > suspect, a sin against God or just best avoided? Having got my current > ap

Re: Global variables, Classes, inheritance

2006-02-03 Thread Michael Spencer
DaveM wrote: > Although I've programmed for fun - on and off - since the mid 70's, I'm > definitely an OO (and specifically Python) beginner. > > My first question is about global variables. Are they, as I'm starting to > suspect, a sin against God or just best avoided? Having got my current > ap

Re: Global variables, Classes, inheritance

2006-02-03 Thread Claudio Grondi
DaveM wrote: > Although I've programmed for fun - on and off - since the mid 70's, I'm > definitely an OO (and specifically Python) beginner. > > My first question is about global variables. Are they, as I'm starting to > suspect, a sin against God or just best avoided? Having got my current > ap

Re: Global Variables in OOP and Python

2006-01-01 Thread Steven D'Aprano
On Sun, 01 Jan 2006 06:48:48 -0800, Kay Schluehr wrote: >> Agree about from module import * being bad, but it is still generally poor >> practice for the same reason using global variables is generally poor >> practice. > > No, I don't think so. The general wisdom is that global variables are > b

Re: Global Variables in OOP and Python

2006-01-01 Thread Kay Schluehr
Steven D'Aprano wrote: > On Fri, 30 Dec 2005 20:00:51 -0500, Mike Meyer wrote: > > > >> The other way I thought of is to create a separate class that consists > >> of the variables and to use the > >> > >> from import * > >> > >> in all of the files (namespaces) where it is needed. > > > > Except

Re: Global Variables in OOP and Python

2005-12-31 Thread Steven D'Aprano
On Sat, 31 Dec 2005 21:21:29 +, Dennis Lee Bieber wrote: > On Sat, 31 Dec 2005 11:37:38 +1100, Steven D'Aprano > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > >> >> Do you mean something like this? >> >> # Module care_and_feeding >> >> import birds >> import foods >>

Re: Global Variables in OOP and Python

2005-12-30 Thread Steven D'Aprano
On Fri, 30 Dec 2005 20:00:51 -0500, Mike Meyer wrote: >> The other way I thought of is to create a separate class that consists >> of the variables and to use the >> >> from import * >> >> in all of the files (namespaces) where it is needed. > > Except for one detail, this is a Pythonesque meth

Re: Global Variables in OOP and Python

2005-12-30 Thread Brian van den Broek
Gary Herron said unto the world upon 30/12/05 08:03 PM: > newbie wrote: > > >>Hello, >> >>I have questions about global variables in OOP (in general) and Python >>(in specific). I understand (I think) that global variables are >>generally not a good idea. However, if there are variables that nee

Re: Global Variables in OOP and Python

2005-12-30 Thread Gary Herron
newbie wrote: >Hello, > >I have questions about global variables in OOP (in general) and Python >(in specific). I understand (I think) that global variables are >generally not a good idea. However, if there are variables that need to >be accessed by a number of classes that exists in separate nam

Re: Global Variables in OOP and Python

2005-12-30 Thread Mike Meyer
"newbie" <[EMAIL PROTECTED]> writes: > So far, I have approached the problem by making the variables > attributes of one class and passing instances of the class as variables > to the other class' methods. That's the standard way to do it in OO languages. > The other way I thought of is to create

Re: Global Variables in OOP and Python

2005-12-30 Thread Steven D'Aprano
On Fri, 30 Dec 2005 15:03:54 -0800, newbie wrote: > Hello, > > I have questions about global variables in OOP (in general) and Python > (in specific). I understand (I think) that global variables are > generally not a good idea. However, if there are variables that need to > be accessed by a num

Re: global variables shared across modules

2005-09-09 Thread Patrick Maupin
MackS wrote: > print "inside fun(): " + global_var ... > How can I get the changed value to "persist" in such a way that it > isn't reset when control leaves fun()? Why is it even reset in the > first place? After all, the module has already been imported (and the > initialization of global_va

Re: Global Variables

2005-04-13 Thread Tim Roberts
"Bob Then" <[EMAIL PROTECTED]> wrote: >If I have a module File >which has some fucontions but I need globals filename and path how can I >set them so I can change them because I tryed. > >filename="log.txt" >path="/home/Bob/" > >def change_filename(): global filename > filename=raw_input()

Re: Global Variables

2005-04-12 Thread George Sakkis
Use 'global': def change_filename(): global filename filename=raw_input() def change_path(): global path path=raw_input() Even better, don't use globals at all; in 99% if the time, there are better ways to achieve the same effect. George -- http://mail.python.org/mailman/listinf

Re: global variables

2005-03-07 Thread Harlin Seritt
You most likely need to construct your script using OOP. Can give you give an example of code you're using when you get this error? This helps a lot. Regards, Harlin -- http://mail.python.org/mailman/listinfo/python-list

Re: global variables

2005-03-07 Thread David S.
M.N.A.Smadi grads.ece.mcmaster.ca> writes: > I need to have a varaible that will contain a value that will be > modified in one file, and when coming back to the same file it > should retain the same value. You must import the module in which the variable lives and qualify it appropriately.

Re: global variables

2005-02-04 Thread Nick Coghlan
A Steve wrote: A Steve wrote: A Steve wrote: There we go, much clearer ;) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mail

Re: global variables

2005-02-03 Thread Steve Holden
Steven Bethard wrote: Steve Holden wrote: M.E.Farmer wrote: Ok it has been a long day, In my reply to Steven Bethard , Steve should read Steven ;) M.E.Farmer Well, since he signs himself "Steve" too I guess we'll just have to put up with the ambiguities. Or perhaps, given my (lack of) typing skil

Re: global variables

2005-02-03 Thread Steven Bethard
Steve Holden wrote: M.E.Farmer wrote: Ok it has been a long day, In my reply to Steven Bethard , Steve should read Steven ;) M.E.Farmer Well, since he signs himself "Steve" too I guess we'll just have to put up with the ambiguities. Or perhaps, given my (lack of) typing skill, I should just start

Re: global variables

2005-02-03 Thread Michael
Probably naming it something other than 'globals' would be a good idea -- otherwise you'll hide the builtin globals() function. But I agree that the attributes of a class instance (as you suggest) or the attributes of a module (as Steve Holden suggests) is probably the right way to go. I like t

Re: global variables

2005-02-03 Thread Mark Jackson
Steve Holden <[EMAIL PROTECTED]> writes: > M.E.Farmer wrote: > > > Ok it has been a long day, > > In my reply to Steven Bethard , Steve should read Steven ;) > > > > M.E.Farmer > > > Well, since he signs himself "Steve" too I guess we'll just have to put > up with the ambiguities. Or perhaps, g

Re: global variables

2005-02-03 Thread Steve Holden
M.E.Farmer wrote: Ok it has been a long day, In my reply to Steven Bethard , Steve should read Steven ;) M.E.Farmer Well, since he signs himself "Steve" too I guess we'll just have to put up with the ambiguities. Or perhaps, given my (lack of) typing skill, I should just start signing myself "Stv

Re: global variables

2005-02-02 Thread M.E.Farmer
Ok it has been a long day, In my reply to Steven Bethard , Steve should read Steven ;) M.E.Farmer -- http://mail.python.org/mailman/listinfo/python-list

Re: global variables

2005-02-02 Thread M.E.Farmer
Steve, Yes I agree ;) Never use builtin names. I know better but missed it somehow. I apologize for any confusion I may have caused. Thank you Steve for the correction. M.E.Farmer Steven Bethard wrote: > M.E.Farmer wrote: > > alex wrote: > >> is it possible to create 'global' variables that can be

Re: global variables

2005-02-02 Thread Larry Bates
One way to to this is by using keyword args: class a: def __init__(self, arg1, arg2, **kwargs): # # Dictionary kwargs will have keyword, value pairs # that can be used as global space. # self.arg1=arg1 self.arg2=arg2 self.__dict__.update(k

Re: global variables

2005-02-02 Thread Steven Bethard
M.E.Farmer wrote: alex wrote: is it possible to create 'global' variables that can be seen in all other classes? What about using a class? Py> class globalVar: ...pass Py> globals = globalVar() Probably naming it something other than 'globals' would be a good idea -- otherwise you'll hide the

Re: global variables

2005-02-02 Thread M.E.Farmer
alex wrote: > Hi, > > is it possible to create 'global' variables that can be seen in all > other classes? > > Alex Hello, What about using a class? Py> class globalVar: ...pass Py> globals = globalVar() Now you can assign 'variables' to it. And use it anywhere you need it. Py> globals.imag

Re: global variables

2005-02-02 Thread Steve Holden
alex wrote: Hi, is it possible to create 'global' variables that can be seen in all other classes? Alex Not sensibly, though you can mess around with the __builtin__ namespace to make values accessible without qualification. The usual solution is to maintain a config module that establishes defa

  1   2   >