2017年10月26日 星期四

How to determine and change file character encoding

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')

沒有留言:

demo_article

使用 msty.app 和 Knowledge Stacks 建立個人知識庫系統 說明 嘗試利用local llm自動從文字檔轉成影音檔 利用AI自動對文件檔產生影音檔案 - YouTube 引言 在資訊爆炸的時代,我們每天接收大量的資訊,但如何有效地管理...