jeremy at alum.mit.edu
Fri Feb 9 18:55:12 CET 2001
In article <96059d$din$1 at news.mathworks.com>,
Joshua Marshall <jmarshal at mathworks.com> wrote:
> > But they *do* complain about having to make explicit
> > references to 'self', which is the analogous thing there.
> Still this is a different issue than lexical scoping. Consider:
> class T:
> def m(self):
> print self.x
> T.x = 'foo'
> Here, T().m() prints "foo". Lexically, x is not defined in m's scope.
> I believe it was a good decision to require going through self to
> access class/object fields. This is very different than something
> def f():
> x = 1
> def g():
> print x
> where x is lexically in g's scope.
I agree that these examples are very different. In the first, the
variable name is self and x is an attribute. In the second, x is itself
a variable. Python has very different rules for name lookup and
The few complaints I have seen about nested scopes on this list all
describe dynamic behavior that is probably better done with objects and
attributes. While nested scopes are useful, many of the uses people put
them to in other languages are probably best done with instances in
-- Jeremy Hylton, <http://www.python.org/~jeremy/>
Sent via Deja.com
More information about the Python-list