удалить один диапазон Unicode из текстового файла Unicode в Python3 - PullRequest
0 голосов
/ 03 февраля 2011

У меня есть текстовый файл Unicode, состоящий из диапазонов от q до r и от s до t. Я хочу удалить диапазон от s до t (на китайском языке), оставляя q на r (на английском).

Как я могу это сделать в Python3?

1 Ответ

2 голосов
/ 03 февраля 2011

Используйте метод перевода строки. Цитировать из документа 3.1.3 Std Lib:

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.
...