python 判斷控制符 unicode str

import codecs
f = codecs.open('unicode.rst', encoding='utf-8')



def rm_control_characters(string):
    return "".join(ch if not unicodedata.category(ch)=='Cc' else ',' ch in unicode(string))

>>> print u'Hello, 你好, bye.'.encode('unicode-escape')
Hello, \u4f60\u597d, bye.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章