1) You can use file command to see the file character encoding
# file -bi httpd.log.20171026.0001
text/plain; charset=utf-8
# file -bi httpd.log.20171025.0001
text/plain; charset=us-ascii
2) how to write unicode support to file in python 2.7
use codecs.open to replace open directly .
[Ascii code]
fp = open(name, 'a')
[unicode]
import codecs
fp= codecs.open(name,'a',encoding='utf-8')
沒有留言:
張貼留言