At a loss on python scoping.

Shiyao Ma i at introo.me
Tue Mar 26 02:19:21 EDT 2013


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 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130326/1d381ac8/attachment.html>


More information about the Python-list mailing list