0

Trying to run simple python file in python prompt but giving an error:

content of test.py

print("Trying to print this using .py file on anaconda prompt")

Running file from python prompt

(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
>>>
martineau
  • 119,623
  • 25
  • 170
  • 301

2 Answers2

0

You are trying to run it within the python interpreter. So just exit that and run the command on the terminal.

Sai Sreenivas
  • 1,690
  • 1
  • 7
  • 16
0

To execute in shell: python test.py

To execute inside the interpreter: exec(open("test.py").read())

This should help: How to execute a file within the python interpreter?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
undefined
  • 31
  • 1