1. 程式人生 > >寫了一個hello.py,執行出錯,提示 File "" , line 1

寫了一個hello.py,執行出錯,提示 File "" , line 1

寫了一個hello.py,僅有一句,print 'hello world',

執行 python hello.py 出錯,提示:

File "<stdin>" , line 1
python hello.py

解釋:

In the shell you can run shell commands, in the Python command line you can run Python code.

"python hello.py" is a shell command, not Python code, so you should run it in the shell, but not on the Python command line. 

"print "hello"" is Python code, so you can run it on the Python command line, but not in the shell.

故,退出python命令列,直接cd到hello.py所在目錄,執行python hello.py,成功。

初學者有用 轉自:http://blog.csdn.net/scorpiomiracle/article/details/8285944