第一种.用for循环不断打开文件写入关闭 测试代码数据如下: import time begin = time.perf_counter() def a(f, lis): f.write(lis + '\n') lis = 'hello' lis2 = 'hello2' for i in range(100): with open('ces.txt', 'a+')as f: # 写入文件 a(f, lis) for j in range(10): with open('ces.txt', 'a+…
在保存网页文字到txt文件下时,出现如下错误 UnicodeEncodeError: 'gbk' codec can't encode character u'\xa9' in position 24051: illegal multibyte sequence 解决方法: with open(“d:/1.txt”,‘a’,encoding=‘gb18030’) as f: GB18030是GBK的父集,所以能兼容GBK不能编码的字符…