【发布时间】:2021-09-13 19:17:02
【问题描述】:
我正在从 python 读取文本文件,当它打印 Unicode 时,它不打印符号。
输入.txt:
hello world
\u00a9
代码:
from pathlib import Path
with open('input.txt','r') as file:
txt = Path('input.txt').read_text()
print(txt)
输出:
hello world
\u00a9
预期输出:
hello world
°
【问题讨论】:
-
请编辑您的问题并进行一些格式化。可读性不是很好。但是可以看到,您的文件不包含
°。您的文件包含文本\u00a9并且已打印。作为文本文件中的字符的字符\u00a9与程序本身中的字符串定义"\u00a9"之间存在差异。检查print("\u00a9")与print(r"\u00a9")。
标签: python text unicode python-unicode