Created
January 23, 2013 09:13
-
-
Save yin8086/4603499 to your computer and use it in GitHub Desktop.
encode('unicode-escape'),decode('unicode-escape')可将'\uxxxx\uxxxx'的字符串与unicode进行自由转换
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Jan 23 11:19:33 2013 | |
@author: Stardrad | |
""" | |
import sys, os, codecs | |
if len(sys.argv) < 2: | |
print u'参数不够' | |
sys.exit(1) | |
elif not os.path.isfile(sys.argv[1]): | |
print u'请输入转换文件' | |
sys.exit(2) | |
srcF = open(sys.argv[1], 'r') | |
dstF = codecs.open(sys.argv[1][:-4]+'.cn.txt', 'wb', 'utf-16') | |
for line in srcF: | |
lnGroup = line.split('=', 1) | |
vName = lnGroup[0].strip() | |
vDesc = lnGroup[1].strip().decode('unicode-escape') | |
dstF.write('%s = %s\n' % (vName, vDesc)) | |
srcF.close() | |
dstF.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment