[Python-Dev] Scoping (corner cases)

Guido van Rossum guido@digicool.com
Sat, 17 Mar 2001 17:19:52 -0500


> What's going on here?
> 
>     Python 2.1b1 (#15, Mar 16 2001, 04:31:43) 
>     [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
>     Type "copyright", "credits" or "license" for more information.
>     >>> x = 1
>     >>> class Foo:
>     ...     print x
>     ... 
>     1
>     >>> class Foo:  
>     ...     print x
>     ...     x = 1
>     ... 
>     1
>     >>> class Foo:
>     ...     print x
>     ...     x = 2
>     ...     print x
>     ... 
>     1
>     2
>     >>> x
>     1
> 
> Can we come up with a consistent story on class scopes for 2.1?

They are consistent with all past versions of Python.

Class scopes don't work like function scopes -- they use LOAD_NAME and
STORE_NAME.

--Guido van Rossum (home page: http://www.python.org/~guido/)