Executing programs

From Training Material
Jump to navigation Jump to search


Starting programs on Windows

Often, it is useful to use a Batch file to start a Python program on Windows. To do so, create an empty file with the ending .bat (Save as.. in IDLE), and write into it:

C:\Python26\python.exe my_script.py

Using command-line options

You can pass options to your program in the batch file. To interpret the options, the sys module contains a list of arguments sys.argv. Note that the first argument is always the name of the program.

import sys
print sys.argv