Tuesday, May 3, 2011

Sometimes I forget the full degree in which Python's "scoping" is broken.

>>> [s for s in [1, 2,3]]
[1, 2, 3]
>>> s
3

2 comments:

  1. Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license()" for more information.
    >>> [s for s in [1, 2,3]]
    [1, 2, 3]
    >>> s
    Traceback (most recent call last):
    File "", line 1, in
    s
    NameError: name 's' is not defined
    >>>

    Can't check right now, but it could be fixed even in 2.7

    ReplyDelete