添加代码
首页 > Python > 片段代码

发布者

Jack.M 发于2010/10/27 14h

查看次数:51586

标签 Tags

谁收藏了?

4人已收藏

Python 对文件进行编码转换

Python 对文件进行编码转换 来自: http://www.oschina.net/code/snippet_12_309
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
import chilkat
 
charset = 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.txt
success = charset.ConvertFile("japanese_shiftJis.txt","japanese_utf8.txt")
if (success != True):
    print charset.lastErrorText()
else:
    print "Success"

评论

提交成功!

您现面为匿名用户,暂不能发表评论。如想评论则请登录注册