在python中使用命令行时出现语法错误 [英] syntax error when using command line in python

查看:18
本文介绍了在python中使用命令行时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 的初学者,目前在使用命令行时遇到问题.我有一个脚本 test.py(它只包含 print("Hello.")),它位于映射 C:Python27 中.在我的系统变量中,我将 python 指定为 C:Python27(我的计算机上也安装了其他版本的 Python).

I am a beginner to python and am at the moment having trouble using the command line. I have a script test.py (which only contains print("Hello.")), and it is located in the map C:Python27. In my system variables, I have specified python to be C:Python27 (I have other versions of Python installed on my computer as well).

我认为这应该足以在命令行中运行 python test.py,但是当我这样做时,我得到了:

I thought this should be enough to run python test.py in the command line, but when I do so I get this:

File "<stdin>", line 1
python test.py
       ^
SyntaxError: invalid syntax

怎么了?提前致谢!

推荐答案

看起来你的问题是你试图在 Python 解释器中运行 python test.py >,这就是您看到追溯的原因.

Looks like your problem is that you are trying to run python test.py from within the Python interpreter, which is why you're seeing that traceback.

确保您没有使用解释器,然后从 bash 或命令提示符或其他任何地方运行 python test.py 命令.

Make sure you're out of the interpreter, then run the python test.py command from bash or command prompt or whatever.

这篇关于在python中使用命令行时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆