尝试在python提示符下运行简单的python文件,但出现错误:
test.py
的内容print("Trying to print this using .py file on anaconda prompt")
从python提示符下运行文件
(base) C:\Users\acharbha>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python C:\Users\acharbha\Documents\python\test.py
File "<stdin>", line 1
python C:\Users\acharbha\Documents\python\test.py
^
SyntaxError: invalid syntax
>>>
答案 0 :(得分:0)
您正在尝试在python解释器中运行它。因此,只需退出并在终端上运行命令即可。
答案 1 :(得分:0)
要在shell中执行:python test.py
要在解释器中执行:exec(open("test.py").read())
这应该有助于: How to execute a file within the python interpreter?