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


Groups > comp.lang.python > #41861 > unrolled thread

Re: At a loss on python scoping.

Started byTerry Reedy <tjreedy@udel.edu>
First post2013-03-26 03:19 -0400
Last post2013-03-26 03:19 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: At a loss on python scoping. Terry Reedy <tjreedy@udel.edu> - 2013-03-26 03:19 -0400

#41861 — Re: At a loss on python scoping.

FromTerry Reedy <tjreedy@udel.edu>
Date2013-03-26 03:19 -0400
SubjectRe: At a loss on python scoping.
Message-ID<mailman.3723.1364282373.2939.python-list@python.org>
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 this name.
> what's the underlying difference between the above example?

For CPython, both the class A and the instance a have a .__dict__ 
attribute that stores names and values. But that is intended to be 
hidden and transparent  for normal usage.


-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web