pyhton出错:
python d: est.py
File "<stdin>", line 1
python d: est.py
^
SyntaxError: invalid syntax
原因:
出错是因为你已经进入python解释器,而不是 在cmd环境里
如果要运行helloworld.py这个文件,你需要在cmd里直接运行
D:Usersfliushida>python D:UsersfliushidaDesktop est.py
File "D:UsersfliushidaDesktop est.py", line 1
SyntaxError: Non-UTF-8 code starting with 'xd1' in file D:UsersfliushidaDesktop est.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:Usersfliushida>python D:UsersfliushidaDesktop est.py
实验成功!