Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41875

Re: At a loss on python scoping.

References <CAJQX3DyT53ocRcxW+1+xRWON2wzoAwEEkEO-zFTXBRm_v5KCOQ@mail.gmail.com> <CAPTjJmoeW9sZ-PCNkJzXr7PCZKEgDvZrdE_URz_RBExDDAH5vA@mail.gmail.com>
Date 2013-03-26 18:35 +0800
Subject Re: At a loss on python scoping.
From Shiyao Ma <i@introo.me>
Newsgroups comp.lang.python
Message-ID <mailman.3730.1364294131.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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@gmail.com> wrote:

> On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma <i@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: At a loss on python scoping. Shiyao Ma <i@introo.me> - 2013-03-26 18:35 +0800

csiph-web