magigo / data_science_tool_book_code

9 stars 5 forks source link

SyntaxError was prompted while execute hello.py #4

Closed aisharing closed 6 years ago

aisharing commented 6 years ago

I totally wrote as the "Hello.py", but met the following error: SyntaxError: Non-ASCII character '\xe4' in file E:\Program Files\Learning\Python\Hello.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ f or details

aisharing commented 6 years ago

Python version: Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AM D64)] on win32

aisharing commented 6 years ago

The error I met was caused by the code I wrote in Sublime Text 3, there is no encoding for Chinese charactor, after I wrote the same code in Notepad++ and set the encoding with GB2312, the Hello.py could be run as normal:

! /usr/bin/python

-- coding: utf-8 --

print("你好,世界")

aisharing commented 6 years ago

C:\Users\Idea>python E:\learning\Python\Hello_02.py 你好,世界