在Interpretor中运行Python脚本
问题描述:
我自学python并下载了最新版本的python 2以及notepad ++。在Interpretor中运行Python脚本
我在记事本这个脚本++保存为Enter_your_name.py
#Program that Welcomes user
ask='Enter your name:'
raw_input(ask)
当我去到Python解释器并发出命令
python Enter_your_name.py
我得到一个语法错误。
这是因为我没有在正确的目录?
编辑
>>>python Enter_your_name.py
File "(stdin)", line 1
python Enter_your_name.py
^
SyntaxError: invalid syntax
>>>
答
打开命令提示符或终端在当前目录,然后键入:
python Enter_your_name.py
否则有从IDLE中直接运行程序的选项下拉菜单。问题是你得到一个语法错误,而不是找不到文件错误。这表明您尝试从Python shell执行命令时出错。
仅供参考摆脱分号,他们不需要在Python中。至于你的语法错误,请编辑你的文章以包含完整的错误和回溯。 – CoryKramer 2015-02-08 20:39:25
您可以通过命令行而不是解释器来调用脚本。 – 2015-02-08 20:39:36
[如何从IDLE交互式shell运行python脚本?](http://stackoverflow.com/questions/17247471/how-to-run-a-python-script-from-idle-interactive-shell) – 2015-02-08 20:43:30