我不说话,只写代码。
import re
if not re.match('[\\x00\\xff\\xfe]', c):
return True
if __name__ == '__main__':
save = open('save.txt', 'w') # save.txt是转换之后的utf-8文件
try:
with open('sec.txt', 'rb') as f: # sec.txt是以Unicode编码的文件,不限于txt格式
for line in open('sec.txt'):
line = f.readline()
line = filter(filter_null, line)
line = line[:-1] # 去掉多余的换行符
line = line.encode('utf-8')
print line
save.writelines(line)
finally:
save.close()
with open('save.txt', 'r') as f_utf8:
print f_utf8.read()
pass