Pol*_*Pol 9 python windows unicode python-2.x python-unicode
在我正在尝试输出俄语字符的控制台它给了我??????????????
谁知道为什么?
我尝试写入文件 - 在这种情况下相同的情况.
例如
f=open('tets.txt','w')
f.write('some russian text')
f.close
Run Code Online (Sandbox Code Playgroud)
里面的文件是 - ??????????????????????
要么
p="some russian text"
print p
?????????????
Run Code Online (Sandbox Code Playgroud)
在额外的记事本中,不允许我用俄文字母保存文件.我这样说:
此文件包含Unicode格式的字符,如果将此文件另存为ANSI编码的文本文件,则会丢失该字符.要保留Unicode信息,请单击下面的"取消",然后从"编码"下拉列表中选择一个Unicode选项.继续?
如何调整我的系统,所以我不会有这个问题.
Phi*_*ipp 15
这是一个经过深思熟虑的例子,请阅读评论:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# The above encoding declaration is required and the file must be saved as UTF-8
from __future__ import with_statement # Not required in Python 2.6 any more
import codecs
p = u"????????????" # note the 'u' prefix
print p # probably won't work on Windows due to a complex issue
with codecs.open("tets.txt", "w", "utf-16") as stream: # or utf-8
stream.write(p + u"\n")
# Now you should have a file called "tets.txt" that can be opened with Notepad or any other editor
Run Code Online (Sandbox Code Playgroud)
小智 8
尝试使用编解码器打开文件
import codecs
Run Code Online (Sandbox Code Playgroud)
然后
writefile = codecs.open('write.txt', 'w', 'utf-8')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
32788 次 |
最近记录: |