Unsupported characters in input In Python IDLE

2019-01-28 09:23发布

问题:

suffixes = {
    1: ["ो", "े", "ू", "ु", "ी", "ि", "ा"]}

When I done message given by IDLE is

Unsupported characters in input

Also not see the proper font in MS-DOS.

回答1:

What encoding is your source file in?

If it is UTF8, put the comment

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

at the top of the file.



回答2:

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.



回答3:

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.