亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

python3.x - python輸出特殊字符報錯
天蓬老師
天蓬老師 2017-04-17 17:37:51
0
6
552

python版本3.5.1,print 輸出 ? 字符報錯,試了用decode轉(zhuǎn)換也沒用,求大神解決的辦法!

print("\xa9")

UnicodeEncodeError: 'gbk' codec can't encode character 'xa9' in position 0: ill
egal multibyte sequence

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進(jìn)步~~

reply all(6)
大家講道理

python3

It is normal to run under IDLE. The poster didn't tell you how you run it?

The output characters will be converted into the terminal encoding.

The default cmd under windows is cp936.
So when you run it directly, python will try to convert this character into gbk encoding, and this will happen after the conversion fails.

One solution is to execute your code in IDLE.

Method 2, first execute chcp 65001 in cmd to change the default encoding of cmd to unicode, and then execute python
http://imysqldba.blog.51cto.com/1222376/706672

劉奇
# coding=utf-8
a = '?'
print a

Output result:

If you remove # coding=utf-8 in the code, the following exception will be thrown: # coding=utf-8去掉,拋如下異常:

SyntaxError: Non-ASCII character '\xc2' in file D:\web\file_test.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

然后我又寫成這樣:

# coding=utf-8
b = '\xa9'
print b

報錯了:

Decode error - output not utf-8
(這個錯是Sublime的問題,在命令行下未報錯,也什么都沒輸出)

雖然我用的是2.7 rrreee
Then I wrote like this:

rrreee ??Error reported:?? rrreee ??Although I am using 2.7 and the exception is different from the subject, you can refer to it. ??Coding issues have always been one of the biggest headaches for programmers...??
大家講道理

Maybe it’s a problem with the terminal. I use IDLE that comes with python 2.7.6, and no error is reported, but a box is output

左手右手慢動作

This character is regarded as a gbk character. Are you sure the copyright symbol is written like this?

阿神

Try setting the environment variable language

伊謝爾倫

I specially installed 3.5.1 and tried it

Python 3.5.1 (default, Apr 22 2016, 09:00:13) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("\xa9")
?

There seems to be no problem here

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template