【问题标题】:remove one unicode range from a unicode textfile in Python3从 Python3 中的 unicode 文本文件中删除一个 unicode 范围
【发布时间】:2011-02-03 04:14:25
【问题描述】:

我有一个由 q 到 r 和 s 到 t 范围组成的 Unicode 文本文件。我想删除范围 s 到 t(中文),留下 q 到 r(英文)。

如何在 Python3 中做到这一点?

【问题讨论】:

  • 在这种情况下,什么是“范围”? “范围 q 到 r”实际上没有任何意义,因为 q 不是范围,而是一个字母。 :)

标签: unicode python-3.x


【解决方案1】:

使用字符串翻译方法。引用 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.

【讨论】:

    猜你喜欢
    • 2015-07-31
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 2021-09-24
    • 2011-08-23
    • 1970-01-01
    • 2012-08-14
    • 1970-01-01
    相关资源
    最近更新 更多