python中多次dump文件,需要多次load才能读取
发布网友
发布时间:2022-04-26 00:22
我来回答
共1个回答
热心网友
时间:2023-10-24 06:30
创建一个文件,如果想要分多次写入数据data,显然每次都要调要mp,即
[python] view plain copy
def writefile(loop, data):
name = 'wb' + str(loop) + '.txt'
f = open(name, "wb")
cPickle.mp(data,f,True)
cPickle.mp(range(11, 21, 3),f,True)
f.close()
调用两次mp,读取文件的时候,必须两次调用load才行
[python] view plain copy
def readfile(loop, layers):
# Load the dataset
name = 'wb' + str(loop) + '.txt'
f = open(name, 'rb')
data = cPickle.load(f)
print 'load first...'
print data
data = cPickle.load(f)
f.close()
print 'load second...'
print data