execfile in global scope

v.vayer at gmail.com v.vayer at gmail.com
Wed Aug 24 04:50:25 EDT 2005


I need to execfile() from a function in order to set value for a global
variable from inside the executed file. I know there are "globals" and
"locals" optional arguments for execfile, but I just can't figure out
how to use them correctly. Here is an example:

Change.py
=========
x = 555

Main.py
=======

def changevar():
    execfile("change.py")

x = 111   # global var
changevar()
print x   # returns 111 instead of 555




More information about the Python-list mailing list