1/01/2012

Unicode字串轉為ASCII字串



今天在使用Python的ldap lib做帳號管理的介接, 發現使用ldap.add_s設置ldap的userPassword屬性時會發生問題, 後來將字串改為ASCII就解決了! 以下是將unicode轉為ASCII的方法:

title = u"this is a statement"
import unicodedata
print unicodedata.normalize('NFKD', title).encode('ascii','ignore')

'Kluft skrams infor pa federal electoral groe'

Reference from http://docs.python.org/library/unicodedata.html

0 意見:

張貼意見