I want to modify a global variable from a function in Python 2.7
x = 0
def func():
global x
x = 2
If I load this code in the interpreter, and then run func(), x remains 0. How do I modify the value of x from within a function?
EDIT: Here's a screenshot of the interpreter and source code. I'm not sure why it works for others and not for me. http://img18.imageshack.us/img18/9567/screenshotfrom201304222.png
func(), andprint x. I get 2.globals()infunc()to see ifxis included.