import pickle
def test1(path):
g = open(path,'r')
count = 1
list1 = [] # 小甲鱼
list2 = [] # 小客服
for each_line in g:
if '===' in each_line:
f = open('D:\\QQ下载\\boy_%d.txt' % count,'wb')
d = open('D:\\QQ下载\\girl_%d.txt' % count, 'wb')
pickle.dump(list1,f)
pickle.dump(list2,d)
f.close()
d.close()
list1.clear() # 小甲鱼
list2.clear() # 小客服
count += 1
if each_line[:2] == '小甲鱼':
list1.append(each_line)
elif each_line[:2] == '小客服':
list2.append(each_line)
if count == 3:
f = open('D:\\QQ下载\\boy_%d.txt' % count, 'wb')
d = open('D:\\QQ下载\\girl_%d.txt' % count, 'wb')
pickle.dump(list1, f)
pickle.dump(list2, d)
f.close()
d.close()
test1('D:\\QQ下载\\record.txt')
。。。
if each_line[:2] == '小甲鱼': # 这句永远不会相等(2个字符,怎么会等于3个字符呢?)
list1.append(each_line)
elif each_line[:2] == '小客服': # 这也一样错。应该是 [:3]
list2.append(each_line)
总体来看,就是 list1, list2 自始至终都没添加进任何元素,所以最后肯定是空列表。
|