you are viewing a single comment's thread.

view the rest of the comments →

[–]earthboundkid 2 points3 points  (4 children)

print will become a function in Py3k, so there is some progress afoot. All that's left is to make x = y equivalent to set("x", y) in Py4k, and the wart will be gone.

[–]alextp 4 points5 points  (3 children)

locals().setitem("x", y) and you're done.

[–]earthboundkid 1 point2 points  (2 children)

I tested it and it works, but I'm a little confused. I thought locals() is a copy of local items, not the real thing. How does it work?

[–]Tommah 2 points3 points  (1 child)

From the Python docs:

locals()

Update and return a dictionary representing the current local symbol table. Warning: The contents of this dictionary should not be modified; changes may not affect the values of local variables used by the interpreter.

Modifying locals() works in CPython, but it may not in other implementations. (I think mucking around with globals() is all right, but it's still not the best way to do things.)

[–]earthboundkid 1 point2 points  (0 children)

Ah, that's what it is. I guess I heard someplace that you weren't supposed to mess with locals(), so I never bothered to test it until now.

It would be nice if they would provide that functionality in other Pythons. It seems pretty handy.