如何检查一个字符是否属于特定代码页?

问题描述 投票:0回答:1

我只想打印不属于特定代码页的字符。

我可以使用什么功能来实现此目的?

with open('in.txt', 'r', encoding="utf-16-le") as f:
    while True:
        c = f.read(1)
        if not c:
            break
        if not c.isprintable():
            continue
        if not ?????(c):
            print(c)
python python-3.x unicode python-unicode codepages
1个回答
0
投票

我猜你的意思是,打印 in.txt 中不属于代码点列表的那些字符!

with open('in.txt', 'r', encoding="utf-16-le") as f:
    while True:
        c = f.read(1)
        if not c:
            break
        if not c.isprintable():
            continue
        if ord(c) not in code_page_range:
            print(c)

其中 code_page_range 是不需要的代码点列表! ord() 为您提供给定字符的 unicode 代码点。我希望这能回答您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.