马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
测试题:
0.
把python里的数据以二进制的形式,永久存储在磁盘的文件里.
1.
pickle.dump(数据,文档)
2.
pickle.load(文档)
3.
可以,后缀只是一种便于记忆的存储方式,不耽误数据本身的有效性.
动动手:
0.
import pickle
def read_txt(path):
global f
f = open(path,encoding = 'GBK')
for each_line in f:
if each_line[:6] != '======':
(name,speaking) = each_line.split(':')
if name == '小甲鱼':
boy.append(speaking)
if name =='小客服':
girl.append(speaking)
else:
make_pickle(boy,girl)
def make_pickle(boy,girl):
global count
boy_file = open('/Users/yufan/Documents/python编程/31/31dds0/boy_%d.txt' % count,'wb')
girl_file = open('/Users/yufan/Documents/python编程/31/31dds0/girl_%d.txt' % count,'wb')
pickle.dump(boy,boy_file)
pickle.dump(girl,girl_file)
girl_file.close()
boy_file.close()
count += 1
boy = []
girl = []
def make_txt(path):
global count
global boy
global girl
count = 1
boy = []
girl = []
read_txt(path)
make_pickle(boy,girl)
f.close()
path = input('请输入路径:')
make_txt(path)
##'/Users/yufan/Documents/python编程/31/31dds0/record.txt'
|