Python error: SyntaxError: Non-ASCII character solution, nonasciicharacter
Python error: SyntaxError: Non-ASCII character Solution
(1) Problem Description
When writing Python code, it is useful to output Chinese characters, but the above error is found after running. SyntaxError: Non-ASCII character '\ xe4' in file./common. py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
The connection to solve the problem is provided in the error prompt, so click to view it. Click here to open the link.
(2) Problem Solving
After learning the connection given in the error code, it is found that it is an encoding problem. If there are non-ASCII characters in python, you must declare the character format at the beginning of the Code. There are three methods to declare characters:
Select one of the three types, and add the specified encoding format at the beginning of the Code. It will solve the problem just now.
For example, I added:
#! /Usr/bin/python #-*-coding: UTF-8 -*-
This solves the problem of displaying Chinese characters.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!