各位高手,小的最近在練習寫python讀寫檔案的程式
http://www.cmlab.csie.ntu.edu.tw/~left/test/
用的是3.2板的
但一直出現下面的error
UnicodeDecodeError: 'cp950' codec can't decode bytes in position
349-350: illegal multibyte sequence
程式如下 是否可以請大大幫忙一下要怎麼改呢?
#-*- coding:utf-8 -*-
import glob
import os
def remove(filename):
s=filename.split("\\")
try:
with open(filename) as fin, open("./output//"+s[1],"w") as fout:
for each_line in fin:
if each_line.find("^ 返回文章列表")!= -1:
break
for each_line in fin:
if each_line.find("你現在看到的首頁 Layout")!= -1:
break
else:
print(each_line,end="",file=fout)
except IOError as ioerr:
print('File error:'+ str(ioerr))
#except UnicodeDecodeError:
# pass
cwd=os.getcwd()
os.chdir(cwd)
if not os.path.exists("output"):
os.mkdir("output")
files = glob.glob('./test//*')
for file in files:
remove(file)
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.175.211
※ 編輯: left 來自: 140.112.175.211 (06/10 20:50)
※ 編輯: left 來自: 140.112.175.211 (06/10 21:21)
推
06/10 21:44, , 1F
06/10 21:44, 1F
→
06/10 21:45, , 2F
06/10 21:45, 2F
→
06/10 22:30, , 3F
06/10 22:30, 3F
→
06/10 22:31, , 4F
06/10 22:31, 4F
→
06/10 22:31, , 5F
06/10 22:31, 5F
→
06/11 17:24, , 6F
06/11 17:24, 6F
→
06/11 18:01, , 7F
06/11 18:01, 7F
→
06/11 18:03, , 8F
06/11 18:03, 8F
→
06/11 18:03, , 9F
06/11 18:03, 9F
→
06/11 19:55, , 10F
06/11 19:55, 10F
→
06/11 20:00, , 11F
06/11 20:00, 11F
→
06/12 01:36, , 12F
06/12 01:36, 12F