Re: Question about scope

2008-11-01 Thread Pat
Steven D'Aprano wrote: On Thu, 23 Oct 2008 11:38:35 -0400, Pat wrote: I have a Globals class. Well, that's your first mistake. Using global variables in a class is no better than using bare global variables. They're still global, and that's a problem: http://weblogs.asp.net/wallen/archive

Re: Question about scope

2008-10-28 Thread Kirk Strauser
At 2008-10-24T01:08:12Z, Pat <[EMAIL PROTECTED]> writes: > ---> myGlobals.py file: > > class myGlobals(): > remote_device_enabled = bool > > ---> my initialize.py file: > > from myGlobals import * > def initialize(): > myGlobals.remote_device_enabled = True > > ---> my main.py file: > > im

Re: Question about scope

2008-10-26 Thread Bruno Desthuilliers
Lawrence D'Oliveiro a écrit : In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote: Why is it a class attribute instead of an instance attribute? Singleton class. Possibly, yes (and I believe it is the case, but...). Or the OP doesnt have a good enough understanding of Python's object mod

Re: Question about scope

2008-10-24 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote: > Why is it a class attribute instead of an instance attribute? Singleton class. -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about scope

2008-10-24 Thread Bruno Desthuilliers
Pat a écrit : (snip) Stripping out the extra variables and definitions, this is all that there is. Whether or not this technique is *correct* programming is irrelevant. It's obviously relevant. If it was correct, it would work, and you wouldn't be asking here !-) I simply want to know wh

Re: Question about scope

2008-10-23 Thread Steven D'Aprano
On Thu, 23 Oct 2008 21:08:12 -0400, Pat wrote: > Stripping out the extra variables and definitions, this is all that > there is. > Whether or not this technique is *correct* programming is irrelevant. Oh rly? Well, sure, you can write bad code if you like, and make your actual job much harder.

Re: Question about scope

2008-10-23 Thread Steven D'Aprano
On Thu, 23 Oct 2008 11:38:35 -0400, Pat wrote: > I have a Globals class. Well, that's your first mistake. Using global variables in a class is no better than using bare global variables. They're still global, and that's a problem: http://weblogs.asp.net/wallen/archive/2003/05/08/6750.aspx >

Re: Question about scope

2008-10-23 Thread Pat
Bruno Desthuilliers wrote: Pat a écrit : I have a Globals class. Not sure it's such a great idea, but anyway... What's the use case for this class ? There are perhaps better (or at least more idiomatic) solutions... In it, I have a variable defined something like this: remote_device_enab

Re: Question about scope

2008-10-23 Thread Bruno Desthuilliers
Pat a écrit : I have a Globals class. Not sure it's such a great idea, but anyway... What's the use case for this class ? There are perhaps better (or at least more idiomatic) solutions... In it, I have a variable defined something like this: remote_device_enabled = bool Could you show

Re: Question about scope

2008-10-23 Thread Lave
Newbie too. I think you shoud qualify Global with the module name. On 10/23/08, Pat <[EMAIL PROTECTED]> wrote: > I have a Globals class. > > In it, I have a variable defined something like this: > > remote_device_enabled = bool > > In one module, I assign True/False to Globals.remote_device_enable

Question about scope

2008-10-23 Thread Pat
I have a Globals class. In it, I have a variable defined something like this: remote_device_enabled = bool In one module, I assign True/False to Globals.remote_device_enabled. Once set, this value never changes. In another module, at the top after the imports statements, I tried this: from

let me simplify my question about scope of vars

2006-12-22 Thread Pyenos
"code" var=1 class CLASS: def METHOD1: def METHOD2: var+=var return var METHOD2() #line8 return var METHOD1() #line10 Q1: does class CLA

Re: question about scope

2006-10-01 Thread John Salerno
Steve Holden wrote: > John Salerno wrote: >> James Stroud wrote: >> >> >>> This is because that list is an attribute of the class. Instances have a >>> reference of this class attribute, but it can be replaced by an >>> attribute of the instance with self (self is a reference to the instance >>>

Re: question about scope

2006-10-01 Thread Steve Holden
John Salerno wrote: > James Stroud wrote: > > >>This is because that list is an attribute of the class. Instances have a >>reference of this class attribute, but it can be replaced by an >>attribute of the instance with self (self is a reference to the instance >>and not the class. This exampl

Re: question about scope

2006-10-01 Thread John Salerno
James Stroud wrote: > This is because that list is an attribute of the class. Instances have a > reference of this class attribute, but it can be replaced by an > attribute of the instance with self (self is a reference to the instance > and not the class. This example might help: Ah, I see! S

Re: question about scope

2006-10-01 Thread Steve Holden
John Salerno wrote: > Steve Holden wrote: > > >>The methods do indeed look in their enclosing class, but only for >>self-relative references. These are sought first in the instance, then >>in the instance's class, then in the instance's class's superclass, and >>so on up to the ultimate superc

Re: question about scope

2006-09-30 Thread James Stroud
John Salerno wrote: > Steve Holden wrote: > >> The methods do indeed look in their enclosing class, but only for >> self-relative references. These are sought first in the instance, then >> in the instance's class, then in the instance's class's superclass, >> and so on up to the ultimate super

Re: question about scope

2006-09-30 Thread John Salerno
Steve Holden wrote: > The methods do indeed look in their enclosing class, but only for > self-relative references. These are sought first in the instance, then > in the instance's class, then in the instance's class's superclass, and > so on up to the ultimate superclass. In other words, all a

Re: question about scope

2006-09-30 Thread Steve Holden
John Salerno wrote: > I have the following code: > > > > class DataAccessFrame(wx.Frame): > > menu_items = [('File', 'New Database', 'New Record', 'Open > Database...', > 'Open Record...', 'Save Record', 'Save All Records', > 'Close Record', 'Close

question about scope

2006-09-30 Thread John Salerno
I have the following code: class DataAccessFrame(wx.Frame): menu_items = [('File', 'New Database', 'New Record', 'Open Database...', 'Open Record...', 'Save Record', 'Save All Records', 'Close Record', 'Close Database'), ('Edit',

Re: question about scope

2006-02-22 Thread Magnus Lycka
John Salerno wrote: > But as far as ifs and loops, is there such a thing as scope in them? No. Local scopes are introduced with "def" or "class", nothing else (or did I forget something?). There is nothing in Python that corresponds directly to the { } in C and C++. If you want data to exist in

Re: question about scope

2006-02-17 Thread Brian van den Broek
John Salerno said unto the world upon 16/02/06 09:18 AM: > "Name references search at most four scopes: local, then enclosing > functions (if any), then global, then built-in." > > I understand what global and built-in are, and I thought I understood > the concept of local too, but when I got

Re: question about scope

2006-02-17 Thread Jean-Paul Calderone
On Thu, 16 Feb 2006 15:18:29 GMT, John Salerno <[EMAIL PROTECTED]> wrote: > [snip] > >I understand what global and built-in are, and I thought I understood >the concept of local too, but when I got to this sentence (and the >previous sentence), I became confused about the first two scopes. What's >

Re: question about scope

2006-02-17 Thread John Salerno
Fredrik Lundh wrote: > John Salerno wrote: > >> But my real question is this, which is related to the above: >> >> "Name references search at most four scopes: local, then enclosing >> functions (if any), then global, then built-in." >> >> I understand what global and built-in are, and I thought I

Re: question about scope

2006-02-17 Thread Fredrik Lundh
John Salerno wrote: > > I understand what global and built-in are, and I thought I understood > > the concept of local too, but when I got to this sentence (and the > > previous sentence), I became confused about the first two scopes. What's > > the difference between 'local' and 'enclosing functi

Re: question about scope

2006-02-17 Thread bruno at modulix
John Salerno wrote: > Here's a sentence from Learning Python: > > "Names not assigned a value in the function definition are assumed to be > enclosing scope locals (in an enclosing def), globals (in the enclosing > module's namespace) or built-in (in the predefined __builtin__ names > module Pytho

Re: question about scope

2006-02-16 Thread Sibylle Koczian
John Salerno schrieb: > Here's a sentence from Learning Python: > > "Names not assigned a value in the function definition are assumed to be > enclosing scope locals (in an enclosing def), globals (in the enclosing > module's namespace) or built-in (in the predefined __builtin__ names > module Pyt

question about scope

2006-02-16 Thread John Salerno
Here's a sentence from Learning Python: "Names not assigned a value in the function definition are assumed to be enclosing scope locals (in an enclosing def), globals (in the enclosing module's namespace) or built-in (in the predefined __builtin__ names module Python provides." I have trouble

Re: question about scope

2006-02-16 Thread John Salerno
John Salerno wrote: > I understand what global and built-in are, and I thought I understood > the concept of local too, but when I got to this sentence (and the > previous sentence), I became confused about the first two scopes. What's > the difference between 'local' and 'enclosing functions'?

Re: question about scope

2006-02-16 Thread Steven D'Aprano
On Thu, 16 Feb 2006 15:18:29 +, John Salerno wrote: > What's an example of a local scope without > having a function definition? Loops and if statements, perhaps? List comprehensions: [2*x+1 for x in range(50)] Lambdas: map(lambda y: y-2, [1,2,4,8,16,32]) At the moment the x in list compre

Re: question about scope

2006-02-16 Thread Fredrik Lundh
John Salerno wrote: > But my real question is this, which is related to the above: > > "Name references search at most four scopes: local, then enclosing > functions (if any), then global, then built-in." > > I understand what global and built-in are, and I thought I understood > the concept of lo

Re: question about scope

2006-02-16 Thread Fuzzyman
John Salerno wrote: [snip..] > > Thanks guys. It seems like nested functions were what the authors had in > mind, so that makes a lot more sense now. > > But as far as ifs and loops, is there such a thing as scope in them? For > example, if I assign a variable within an if statement, is it usable