0

I am trying to run a .py script using IDLE which is in a different folder say D:\Python\Practice whereas my python is installed in C:\Python.

I changed the directory to D:\Python\Practice where the script was present through os.chdir command. Then I executed python xyz.py but it is throwing error.

import os
os.chdir("D:\Python\Practice")
python xyz.py

Syntax Error: Invalid Syntax

Sachin Kedar
  • 93
  • 2
  • 7
  • open the IDLE, open your .py file via the new IDLE (File > open file - xyz.py) and run the script, you dont need to write a new script to run the other script – Mr.Riply Oct 02 '19 at 09:10
  • I understand that but I wanted to know how I can execute it with command line. – Sachin Kedar Oct 02 '19 at 09:17
  • "python xyz.py" is invalid syntax – ElmoVanKielmo Oct 02 '19 at 09:40
  • I see, I had similar issues in the past. In my case it was a one time thing, so I just moved my .py script into the Python main folder and then ran it, that was my workaround – Mr.Riply Oct 02 '19 at 10:24

1 Answers1

0

Using Windows CLI, you can navigate to your folder and execute the script as following:

\> D:

D:\>cd D:\Python\Practice

D:\Python\Practice\>python xyz.py

Or simply give the full path of your file in the python command wherever you are:

>python D:\Python\Practice\xyz.py

3bdl1
  • 33
  • 4