At a loss on python scoping.

Shiyao Ma i at introo.me
Tue Mar 26 06:35:28 EDT 2013


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 the first step is to look inside a, maybe in the __dict__?
As proved in my ipython, the __dict__ is empty.
So, it will look up in A.__dict__
Here comes my first question, where does the scope of class A falls in when
considering LEGB.

On Tue, Mar 26, 2013 at 2:29 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma <i at introo.me> 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/python-list
>



-- 
My gpg pubring is available via: gpg --keyserver
subkeys.pgp.net--recv-keys 307CF736

More on: http://about.me/introom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130326/f6d7e023/attachment.html>


More information about the Python-list mailing list