python 将复杂数据类型(list、dict)存储到文件 以及 读入 pickle模块

存储:

  

import pickle

    fileHandle = open ( 'pickleFile.txt', 'w' ) 
    testList = [ 123, { 'Calories' : 190 }, 'Mr. Anderson', [ 1, 2, 7 ] ] 
    pickle.dump ( testList, fileHandle ) 
    fileHandle.close() 

 

读取

import pickle
    fileHandle = open ( 'pickleFile.txt' ,'r') 
    testList = pickle.load ( fileHandle ) 
    fileHandle.close() 

 

posted @ 2014-03-15 20:49  aldin  阅读(2090)  评论(0编辑  收藏  举报