【发布时间】:2013-09-13 11:02:29
【问题描述】:
昨天我写了以下function 将integer 转换为Persian:
def integerToPersian(number):
listedPersian = ['۰','۱','۲','۳','۴','۵','۶','۷','۸','۹']
listedEnglish = ['0','1','2','3','4','5','6','7','8','9']
returnList = list()
listedTmpString = list(str(number))
for i in listedTmpString:
returnList.append(listedPersian[listedEnglish.index(i)])
return ''.join(returnList)
当您调用它时,例如:integerToPersian(3455),它是return ۳۴۵۵,
۳۴۵۵ 相当于Persian 和Arabic language 中的3455。当你阅读
一个数字,例如从databae 读取,并希望在widget 中显示,这个
function 很有用。
我从http://unicode.org下载了unicode的codes charts,因为我需要写PersianToInteger('unicodeString')根据它应该得到utf-8作为参数和utf-8存储2 bytes,我也是新手pytho。
我的问题是,如何存储2bytes? ,utf8 如何存储,如何将unicode string 拆分为另一种格式? unicode code charts怎么用?
注意:我发现可以使用int() built-in fuinction,但我不能使用它。也许你可以
【问题讨论】:
-
你用的是python2还是python3?
-
请注意,Python 附带了来自
unicodedata模块中内置 Unicode 图表的所有信息(并且保证它们与您的 Python 版本使用的 Unicode 版本相匹配)。跨度> -
作为旁注,
listedEnglish.index(i)本来就是int(i),对吧?这要简单得多,这意味着您可以完全摆脱listedEnglish...
标签: python unicode utf-8 unicode-string python-unicode