[Tutor] Running Files with Command Lines

Alan Gauld alan.gauld at btinternet.com
Sun Feb 12 10:06:41 CET 2012

On 12/02/12 07:24, Yony Torres wrote:

> "Once you’ve saved this text file, you can ask Python to run it
 > by listing its full filename as the first argument to a
 > python command, typed at the system shell prompt:"
> % python script1.py

Lets break down what this line is saying. It comprises three parts:
1) the operating system command prompt, shown as '%'
2) the python interpreter shown as 'python'
3) the python script to be interpreted, shown as script1.py

You only need to type the last two since your OS will provide the first 
one. On Windows that will usually look like


or similar.

The path to the interpreter normally looks like


And the path to your script we know is:

c:\users\myusername\documents\varios 2\python journey\script1.py

And because you have a space in there we must put quotes aroundd it:

"c:\users\myusername\documents\varios 2\python journey\script1.py"

So the command that you type in your CMD shell window should look like:

C:\python31\python "c:\users\myusername\documents\varios 2\python 

all on one line.

Now we can shorten that significantly by setting Python to be in the 
PATH. That way you don't need to provide the full path to Python.
(To set the path follow the instructions in my tutor in the "Windows 
Command prompt" box in the "Getting started" topic.)

Next, you can change into the folder with your script using

CD "c:\users\myusername\documents\varios 2\python journey"

(The prompt should now show the path to your script)

Now you only need to type:

python script1.py


Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list