干将博客 mac软件 python学习

python_输入输出

 存储器

python中可以把对象存到文件当中,成为永久性的对象。

 

01 #!/usr/bin/python
02 # Filename: pickling.py
03  
04 import cPickle as p
05 #import pickle as p
06  
07 shoplistfile = 'shoplist.data'
08 # The name of the file where will be store the object
09  
10 shoplist = ['apple''mango''carrot']
11  
12 # Write to the file
13 = file(shoplistfile, 'w')
14 p.dump(shoplist, f) # dump the object to a file
15 f.close()
16  
17 del shoplist #remove the shoplist
18  
19 # Read back from the storage
20 = file(shoplistfile)
21 storedlist = p.load(f)
22 print storedlist

 

标签:PYTHON
分类:学习与教程| 发布:干将| 查看: | 发表时间:2011-7-29
原创文章如转载,请注明:转载自干将个人博客 http://www.ganjiang.org/
本文链接:http://www.ganjiang.org/post/55.html

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。