How to Run a Python Program

PythonServer Side ProgrammingProgramming

There are three different ways to start Python −

Interactive Interpreter

You can start Python from Unix, DOS, or any other system that provides you a command-line interpreter or shell window.

Enter python the command line.

Start coding right away in the interactive interpreter.

$python # Unix/Linux
or
python% # Unix/Linux
or
C:> python # Windows/DOS

Here is the list of all the available command line options −

Sr.No.Option & Description
1-d
It provides debug output.
2-O
It generates optimized bytecode (resulting in .pyo files).
3-S
Do not run import site to look for Python paths on startup.
4-v
verbose output (detailed trace on import statements).
5-X
disable class-based built-in exceptions (just use strings); obsolete starting with version 1.6.
6-c cmd
run Python script sent in as cmd string
7file
run Python script from given file

Script from the Command-line

A Python script can be executed at command line by invoking the interpreter on your application, as in the following −

$python script.py # Unix/Linux
or
python% script.py # Unix/Linux
or
C: >python script.py # Windows/DOS

Note − Be sure the file permission mode allows execution.

Integrated Development Environment

You can run Python from a Graphical User Interface (GUI) environment as well, if you have a GUI application on your system that supports Python.

  • Unix − IDLE is the very first Unix IDE for Python.
  • Windows − PythonWin is the first Windows interface for Python and is an IDE with a GUI.
  • Macintosh − The Macintosh version of Python along with the IDLE IDE is available from the main website, downloadable as either MacBinary or BinHex'd files.

If you are not able to set up the environment properly, then you can take help from your system admin. Make sure the Python environment is properly set up and working perfectly fine.

raja
Published on 24-Jan-2020 11:09:45
Advertisements