An expression that rebinds a variable?

Thomas Bellman bellman at lysator.liu.se
Fri May 18 03:28:31 EDT 2007


GreenH <Green.Horn.000 at gmail.com> writes:

> Can I know what kind of expressions rebind variables, of course unlike
> in C, assignments are not expressions (for a good reason)
> So, eval(expr) should bring about a change in either my global or
> local namespace, where 'expr' is the expression

List comprehensions:

    >>> c
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'c' is not defined
    >>> eval('[ord(c) for c in "parrot"]')
    [112, 97, 114, 114, 111, 116]
    >>> c
    't'

This is supposed to be changed in Python 3.0.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"What sane person could live in this world   !  bellman @ lysator.liu.se
 and not be crazy?"  -- Ursula K LeGuin      !  Make Love -- Nicht Wahr!



More information about the Python-list mailing list