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


Groups > comp.lang.python > #41856

Re: At a loss on python scoping.

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

Show all headers | View raw


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

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 <i@introo.me> 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 this name.
> what's the underlying difference between the above example?
>
>
> --
> My gpg pubring is available via: gpg --keyserver subkeys.pgp.net--recv-keys 307CF736
>
> More on: http://about.me/introom
>
>


-- 
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 | NextNext in thread | Find similar | Unroll thread


Thread

Re: At a loss on python scoping. Shiyao Ma <i@introo.me> - 2013-03-26 14:19 +0800
  Re: At a loss on python scoping. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 12:43 +0000

csiph-web