开发者

remove one unicode range from a unicode textfile in Python3

I have a Unicode textfile consisting of ranges q to r and s to t. I want to remove range s to t (which is in Chinese开发者_开发百科) leaving q to r (which is in English).

How can I do that in Python3?


Use the string translate method. To quote from the 3.1.3 Std Lib doc:

str.translate(map) 
Return a copy of the s where all characters have been mapped through the map 
which must be a dictionary of Unicode ordinals (integers) to Unicode ordinals, 
strings or None. Unmapped characters are left untouched. Characters mapped to 
None are deleted.

You can use str.maketrans() to create a translation map from 
character-to-character mappings in different formats.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜