Skip to Main Content
Python Programming On Win32
book

Python Programming On Win32

by Andy Robinson, Mark Hammond
January 2000
Intermediate to advanced content levelIntermediate to advanced
672 pages
21h 46m
English
O'Reilly Media, Inc.
Content preview from Python Programming On Win32

Using the Windows Command Prompt

Both the Windows 95/98 and NT/2000 families come with a command prompt allowing users to run programs from a command-line interface. The Windows command prompt has a long and not-so-glorious history; it has grown from the first versions of MS-DOS and still uses the same basic syntax.

Running Python programs

For these discussions, let’s assume you have a file named C:\Scripts\hello.py, and this file consists of the single line:

print "Hello from Python"

A first attempt to run this program may surprise you:

C:\Scripts>python.exe hello.py
The name specified is not recognized as an
internal or external command, operable program or batch file.

C:\Scripts>

Although Python.exe has been installed, it hasn’t modified the system environment variable PATH: Windows doesn’t know how to find Python.exe. Windows NT does, however, know how to run .py files directly. Thus, if you ask the command prompt to execute hello.py, it will:

C:\Scripts>hello.py
Hello from Python

C:\Scripts>

Take this one step further and avoid the use of the .py extension, making a Python program appear like a .exe, .com, or .bat file. Windows NT supports this using the PATHEXT environment variable. You can view the current settings of this variable by entering the command:

C:\Scripts>echo %PATHEXT%
.exe;.bat;.cmd

C:\Scripts>

This is a list of the default extensions Windows searches for when a command is executed. You can add Python files to this list (and check the change was successful) by executing: ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen

Publisher Resources

ISBN: 1565926218Supplemental ContentErrata Page