cPickling and variable scope problem
Cere Davis
cere at u.washington.edu
Mon Mar 17 00:07:56 EST 2003
Using Python2.2
I've got a piece of code that goes something like this:
import sys,os,cPickle
def getData():
data["x"]="y"
def stash():
ouf=open("stuff",'wb')
cPickle.dump(data,ouf)
ouf.close()
def unstash():
inf=open("stuff",'rb')
data=cPickle.load(inf)
inf.close()
def main():
global data
data={}
if os.path.exists("stuff"):
unstash()
print data.keys()
print data.values()
sys.exit(0)
getData()
stash()
if __name__ == '__main__':
main()
But I don't get any output for the data.keys() or data.values() from
"main". Can someone tell me what's wrong here?
Perhaps obvious, but I am not seeing the problem.....
Thanks,
-Cere
More information about the Python-list
mailing list