Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69676
| From | Rotwang <sg552@hotmail.co.uk> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Scoping rules for class definitions |
| Date | 2014-04-04 19:37 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <lhmu69$1nu$1@dont-email.me> (permalink) |
Hi all. I thought I had a pretty good grasp of Python's scoping rules,
but today I noticed something that I don't understand. Can anyone
explain to me why this happens?
>>> x = 'global'
>>> def f1():
x = 'local'
class C:
y = x
return C.y
>>> def f2():
x = 'local'
class C:
x = x
return C.x
>>> f1()
'local'
>>> f2()
'global'
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Scoping rules for class definitions Rotwang <sg552@hotmail.co.uk> - 2014-04-04 19:37 +0100
Re: Scoping rules for class definitions Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-04 12:55 -0600
Re: Scoping rules for class definitions Rotwang <sg552@hotmail.co.uk> - 2014-04-08 23:09 +0100
csiph-web