O'Reilly logo

Programming Python, Second Edition by Mark Lutz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Running Python Programs

Python code can be typed at a >>> interactive prompt, run from a C program, or placed in text files and run. There is a variety of ways to run code in files:

Running from a command line

Python files can always be run by typing a command of the form python file.py in your system shell or console box, as long as the Python interpreter program is on your system’s search path. On Windows, you can type this command in an MS-DOS console box; on Linux, use an xterm.

Running by clicking

Depending on your platform, you can usually start Python program files by double-clicking on their icons in a file explorer user interface. On Windows, for instance, .py Python files are automatically registered such that they can be run by being clicked (as are .pyc and .pyw files).

Running by importing and reloading

Files can also be run by importing them, either interactively or from within another module file. To rerun a module file’s code again without exiting Python, be sure to run a call like reload(module).

Running files in IDLE

For many, running a console window and one or more separate text editor windows constitutes an adequate Python development environment. For others, IDLE -- the Python Integrated Development Environment (but really named for Monty Python’s Eric Idle) -- is a development environment GUI for Python. It can also be used to run existing program files or develop new systems from scratch. IDLE is written in Python/Tkinter, and thus is portable across ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required