Re: At a loss on python scoping.

2013-03-26 Thread Steven D'Aprano
On Tue, 26 Mar 2013 14:19:21 +0800, Shiyao Ma wrote: > PS, I now python's scoping rule is lexical rule (aka static rule). How > does LEGB apply to class? It doesn't. Python does not use the same lookup rules for attributes and unqualified names. Attribute lookups follow inheritance rules. `inst

Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
After read Dave's answer, I think I confused LEGB with attribute lookup. So, a.r has nothing to do with LEGB. On Tue, Mar 26, 2013 at 7:03 PM, Shiyao Ma wrote: > Thx, really a nice and detailed explanation. > > > On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel wrote: > >> On 03/26/2013 02:17 AM, Sh

Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
Thx, really a nice and detailed explanation. On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel wrote: > On 03/26/2013 02:17 AM, Shiyao Ma wrote: > >> Hi, >> suppose I have a file like this: >> class A: >> r = 5 >> def func(self, s): >> self.s = s >> a = A() >> print(a.r)# this s

Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
Sorry for my obscure description. "the name of r" , AFAIK, everything in python is just a reference. For example, a = 3, means a points to a small integer; b= [] means b points to a list somewhere in the memory. So I call r as the name of r. To clarify my question. say I wanna look up a.r I guess

Re: At a loss on python scoping.

2013-03-26 Thread Dave Angel
On 03/26/2013 02:17 AM, Shiyao Ma wrote: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store

Re: At a loss on python scoping.

2013-03-26 Thread Terry Reedy
On 3/26/2013 2:17 AM, Shiyao Ma wrote: Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store t

Re: At a loss on python scoping.

2013-03-25 Thread Chris Angelico
On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma wrote: > class A: > r = 5 > def func(self, s): > self.s = s > a = A() > print(a.r)# this should print 5, but where does py store the name of r What do you mean by "the name of r"? ChrisA -- http://mail.python.org/mailman/listinfo/py

Re: At a loss on python scoping.

2013-03-25 Thread Shiyao Ma
PS, I now python's scoping rule is lexical rule (aka static rule). How does LEGB apply to class? On Tue, Mar 26, 2013 at 2:17 PM, Shiyao Ma wrote: > Hi, > suppose I have a file like this: > class A: > r = 5 > def func(self, s): > self.s = s > a = A() > print(a.r)# this should

At a loss on python scoping.

2013-03-25 Thread Shiyao Ma
Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference b