cPickling and variable scope problem
Jp Calderone
exarkun at intarweb.us
Mon Mar 17 01:13:23 EST 2003
On Sun, Mar 16, 2003 at 09:07:56PM -0800, Cere Davis wrote:
>
> 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()
"data" is a local in the above function.
>
> 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.....
Jp
--
"Pascal is Pascal is Pascal is dog meat."
-- M. Devine and P. Larson, Computer Science 340
--
up 13 days, 21:59, 8 users, load average: 0.00, 0.00, 0.00
More information about the Python-list
mailing list