每天CookBook之Python-032

  • 清除文本格式
s = 'pýtĥöñ\fis\tawesome\r\n'
print(s)

remap = {
    ord('\t') : ' ',
    ord('\f') : ' ',
    ord('\r') : None
}

a = s.translate(remap)
print(a)

import unicodedata
import sys

cmb_chrs = dict.fromkeys(c for c in range(sys.maxunicode) if unicodedata.combining(chr(c)))
b = unicodedata.normalize('NFD', a)
print(b)
print(b.translate(cmb_chrs))
pýtĥöñis   awesome
pýtĥöñ is awesome
pýtĥöñ is awesome
python is awesome
posted @ 2016-07-14 21:11  4Thing  阅读(106)  评论(0编辑  收藏  举报