我只想打印不属于特定代码页的字符。
我可以使用什么功能来实现此目的?
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)
我猜你的意思是,打印 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 代码点。我希望这能回答您的问题。