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 >>> 
4
  • 1
    execfile('test.py') Commented Jul 6, 2020 at 16:10
  • 2
    You are trying to run a shell/cmd command inside of the python IDLE. Commented Jul 6, 2020 at 16:10
  • @jordanm Just curious, how can you tell it's IDLE? It looks like any other REPL to me. Commented Jul 6, 2020 at 16:22
  • You are trying to run a shell/cmd command inside of the python console. Commented Jul 6, 2020 at 16:33

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.