Unsupported characters in input In Python IDLE

一个人想着一个人 提交于 2019-11-29 14:51:52

What encoding is your source file in?

If it is UTF8, put the comment

# -*- coding: utf-8 -*-

at the top of the file.

If you don't declare encoding in your first or second line in your python source file, then the python interpreter will use ASCII encoding system to decode the characters in the file. As these characters you used couldn't be decoded by ASCII encoding system, errors happended.

The solution is as @RemcoGerlich said. Here is the doc.

The encoding is used for all lexical analysis, in particular to find the end of a string, and to interpret the contents of Unicode literals. String literals are converted to Unicode for syntactical analysis, then converted back to their original encoding before interpretation starts. The encoding declaration must appear on a line of its own.

This seems to be a known bug in the 2.x IDLE console: http://bugs.python.org/issue15809. A fix was made for Python 3.x, but doesn't appear to be backported.

Instead, use an alternative console, such as iPython/Jupyter, or a fully-fledged IDE, such as PyCharm.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!