2009年4月3日星期五
解决supermemo 2006 Q&A txt格式导入时中文不显示的问题
解决supermemo 2006 Q&A txt格式导入时中文不显示的问题
原始的Q&A 文件格式如下,导入sumpermemo后无法显示答案,经过与supermemo导出Q&A txt文件比较后发现,原来需要将中文部分转为unicode的内码格式,才能正常导入。这个就容易了,直接写个python小程序就搞定。
------ 无法显示答案的Q&A txt文件格式------
Q: what
A: 什么
------ supermemo导出Q&A txt文件格式 ------
Q: what
A: 什么
#######################
# python 代码
#######################
def getCode(cd):
oCd = ord(cd)
if oCd > 255 :
return '&#%s;' % oCd
else :
return cd
if __name__ == "__main__":
#不正确格式的Q&A txt文件
f = open('c:/cet.txt','r')
#正确的可以导入的输出文件
o = open('c:/smcet.txt', 'a')
for line in f:
o.write(''.join('%s' % getCode(c) for c in unicode(line)))
f.close()
o.close()
订阅:
博文评论 (Atom)
没有评论:
发表评论