Just start learning Python and follow the code in the book:
#根据给定的年月日以数字的形式打印出来months = [ ' January ', ' Febuary ', ' March ', ' April ', ' may ', ' June ', ' July ', ' August ', ' September ', ' October ', ' November ', ' December ']# With 1~31 number as the end of the list endings = [' st ', ' nd ', ' Rd '] + + * [' th '] + [' st ', ' nd ', ' Rd '] + 7 * [' th '] + [' st ']year = Raw_input (' Year: ') Month = Raw_input (' Month (1-12): ') Day = Raw_input (' Day (1-31) ') month_number = Int (month) day_number = Int (day) #记得要将月份和天数减1 to get the correct index month_name = months[month_number-1]ordinal = day + endings[day_number-1] Print Month_name + ' + ordinal + ', ' + year~
An error occurred while executing:
Syntaxerror:non-ascii character ' \xe6 ' in file print date. py on line 1, but no encoding declared; See http://www.python.org/peps/pep-0263.html for details
Baidu a bit:
The discovery is because Python does not support encoding in the source file by default. The solution has the following three kinds:
First, add the following comment code at the head of the file:
# coding=<encoding Name> For example, you can add # Coding=utf-8
Second, add the following two lines of comment code at the head of the file:
#!/usr/bin/python
#-*-Coding: <encoding name>-*-For example, you can add #-*-Coding:utf-8-*-
Third, add the following two lines of comment code at the head of the file:
#!/usr/bin/python
# Vim:set fileencoding=<encoding name>: For example, you can add # Vim:set Fileencoding=utf-8:
I used the first method to solve! Record it.
Python appears syntaxerror:non-ascii character ' \xe6 ' in file print date. py on line 1, but no encoding declared;