这是我当前写入文件的方式。但是,我不能使用UTF-8?
f = open("go.txt", "w")
f.write(title)
f.close()
如果“标题”是日文/utf-8 格式怎么办?如何修改此代码以便能够编写“标题”而不会出现 ascii 错误?
编辑:那么,我如何读取这个UTF-8格式的文件呢?
f = open("go.txt", "w")
f.write(title)
f.close()
What if "title" is in japanese/utf-8? How do I modify this code to be able to write "title" without having the ascii error?
Edit: Then, how do I read this file in UTF-8?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如何使用 UTF-8:
How to use UTF-8:
这取决于您是否要插入 Unicode UTF-8 字节顺序标记 ,其中我知道的唯一方法是打开一个普通文件并写入:
一般来说,我不想添加 UTF-8 BOM,但以下内容就足够了:
It depends on whether you want to insert a Unicode UTF-8 byte order mark, of which the only way I know of is to open a normal file and write:
Generally though, I don't want to add a UTF-8 BOM and the following will suffice though: