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
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
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
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
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
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.
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
>
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
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
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
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
"code"
var=1
class CLASS:
def METHOD1:
def METHOD2:
var+=var
return var
METHOD2() #line8
return var
METHOD1() #line10
Q1: does class CLA
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
>>>
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
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
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
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
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
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
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',
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
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
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
>
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
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
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
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
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
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'?
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
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
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
32 matches
Mail list logo