Python
对文件进行编码转换
import
sysimport
chilkatcharset
=
chilkat.CkCharset()#
Any string argument automatically begins the 30-day trial.success
=
charset.UnlockComponent("30-day
trial")if
(success !=
True): print
charset.lastErrorText() sys.exit()#
Set the "To" and "From" character encodings:charset.put_FromCharset("shift_JIS")charset.put_ToCharset("utf-8")#
To do file-to-file conversion, call ConvertFile.#
The shift_JIS sample file is downloadable from this URL:#
http://www.chilkatsoft.com/testData/japanese_shiftJis.txtsuccess
=
charset.ConvertFile("japanese_shiftJis.txt","japanese_utf8.txt")if
(success !=
True): print
charset.lastErrorText()else: print
"Success"Python 对文件进行编码转换

本文介绍了使用Python和Chilkat库进行文件编码转换的方法,包括导入必要的库、设置字符集和执行转换操作。
2933

被折叠的 条评论
为什么被折叠?



