pyhton出錯:
python d:\test.py
File "<stdin>", line 1
python d:\test.py
^
SyntaxError: invalid syntax
原因:
出錯是因為你已經進入python解釋器,而不是 在cmd環境里
如果要運行helloworld.py這個文件,你需要在cmd里直接運行
D:\Users\bfliushida>python D:\Users\bfliushida\Desktop\test.py
File "D:\Users\bfliushida\Desktop\test.py", line 1
SyntaxError: Non-UTF-8 code starting with '\xd1' in file D:\Users\bfliushida\Desktop\test.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
經過百度查看其他人的博客,說是Python的默認編碼格式是UTF-8,若指定編碼格式則需在開頭添加如下代碼:
-
# -*- coding: UTF-8 -*-
-
#建議采用該語句
-
或
-
#-*-coding:gb2312-*-
-
問題即可解決!!
D:\Users\bfliushida>python D:\Users\bfliushida\Desktop\test.py
實驗成功!