Python错误:文件&quot;<stdin>&quot; [英] Python Error : File &quot;&lt;stdin&gt;&quot;
问题描述
我正在尝试学习 Python 并尝试在终端中执行一个 python 文件.我在 OS X 上使用 2.7.3 python 版本.我已将终端中的目录更改为文件所在的位置,但在终端中出现错误:
<预><代码>>>>蟒蛇 ex1.py文件<stdin>",第 1 行蟒蛇 ex1.py^语法错误:无效语法ex1.py 文件包含:
打印Hello World!"打印你好再次"打印我喜欢打字."打印这很有趣."打印'耶!印刷.'打印我宁愿你‘不’."打印'我说"不要碰这个.
关于如何解决这个问题的任何想法?谢谢一堆.
>>>蟒蛇 ex1.py
您正在尝试从 Python 解释器中运行您的脚本.你不想那样做.
相反,只需在终端中运行该命令,而不是在解释器中
$ python ex1.py
如果你还在解释器中,你可以按 ctrl+d 离开它并返回'正常'终端
I'm trying to learn Python and am trying to execute a python file in terminal. I'm using 2.7.3 python version on my OS X. I've changed the directory in terminal to where the file is located, but I'm getting an error in terminal:
>>> python ex1.py
File "<stdin>", line 1
python ex1.py
^
SyntaxError: invalid syntax
The ex1.py file contains:
print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
Any ideas on how to fix this? Thx a bunch.
>>> python ex1.py
You are trying to run your script from within a python interpreter. You don't want to do that.
Instead, just run that command in a terminal, not in the interpreter
$ python ex1.py
If you are still in the interpreter, you can press ctrl+d to leave it and return to the 'normal' terminal
这篇关于Python错误:文件&quot;<stdin>&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!