python - 以 UTF-8 写入 txt 文件 - Python
问题描述
解决方案
The issue here is that you're calling open()
on a file without specifying the encoding. As noted in the Python documentation, the default encoding is platform dependent. That's probably why you're seeing different results in Windows and MacOS.
Assuming that the file itself was actually encoded in UTF-8, just specify that when reading the file:
original = open(str(last_uploaded.document), 'r', encoding="utf-8")
推荐阅读
- django - 使用 Django Channels 在模型中添加新记录时创建用户通知的最佳解决方案是什么?
- android - 创建仅设置属性的“假”属性
- c - 找到硬编码号码
- ajax - ASP.net MVC 5 部分视图 Ajax POST 不只更新部分
- c++ - 这段代码打印 x 的值在 5000 左右,但不是 10000,这是为什么呢?
- ansible - 使用 Ansible 在 Route 53 中列出 100 多条记录
- oracle - 相对于时区将 TIMESTAMP 转换为 DATE
- python - VScode 中的 Python 调试
- node.js - 这是在扩展类中未定义的
- python - 为什么 web3.eth.getBlock 给出空答案而 getTransactionReceipt 给出错误?