python - 将存储为变量的 unicode 转换为纯文本(例如:“\u0044”到“D”)
问题描述
我正在从 .htm 文件中解析/提取 unicode,并将它们存储为变量。问题是,我希望它打印为纯文本/字母。这是我的代码:
with open("Peribahasa.htm", "r") as Peribahasa_File:
for line in itertools.islice(Peribahasa_File, 1000, 1150):
for item in line.split("\n"):
if "I[0][1][0][0]" in item:
answer_1 = (((item.strip()).replace("I[0][1][0][0] = '", "")).replace("';", ""))
print(answer_1.encode('utf-8'))
但是,最后的打印行将其打印为 -> b'\u0044' 作为参考, answer_1 变量是 -> \u0044
我只需要将 \u0044 转换为字母 D
任何帮助都将不胜感激!我已经在这几个小时了,谢谢!
我使用 Python 3
解决方案
尝试以下操作:
answer_1.encode().decode('unicode_escape')
推荐阅读
- ios - UISegmentedControl 自定义/扩展
- c++ - 在 QMenuBar/QMenu 上捕获 keyPressEvent?
- javascript - GAE Flex 上的节点获得最大侦听器问题
- authentication - 使用 NFC 非接触式银行卡进行身份验证
- aws-lambda - Alexa 技能 - 如何逐行读取结果集
- href - 使用 jQuery 删除 [href]
- excel - Excel 公式帮助:1 周内,但不超过 1 周
- php - 使用 PHPExcel 从 xlsx 转换为 csv 期间更改日期格式
- r - R:我应该用与函数参数相同的名称命名变量吗?
- iterator - 寻找 H2O 的记录迭代器