The Python window is where you enter code and execute it immediately. But you can also use an Integrated Development Environment (IDE) to create Python files on disk (files with a .py extension). These files, known as scripts, are programs you can execute from either the operating system prompt or by creating a script tool that executes the script. Scripts are text files; any text editor, such as Notepad or VI, can be used to author a script. But using a text editor to create a Python script is a poor choice compared to using an IDE. Whether you are writing a single script or many, a Python IDE will accelerate your development time and is strongly recommended.
Like the Python window, Python IDEs have an interactive window that allows the execution of a single line of Python code, with the resulting messages printed to the window. In addition, Python IDEs have many features to help you enter, edit, check syntax, and debug Python code. The standard Python installation provides a basic Python editor, Integrated Development Environment (IDLE), that also provides search capabilities and a symbolic debugger.
Inevitably, errors occur when you write and execute scripts. An IDE provides a debugging environment that allows you to step through code and interrogate variables, check object validity, and evaluate expressions.
Python IDEs
As there are many Python IDEs to choose from, picking the right one can very well depend on the platform you use (Windows or Linux), specific features, or the cost. At a minimum, a good IDE will have the following features:
- An editor with code completion
- Syntax highlighting
- Code templates
- A code explorer for functions and classes
- Tools for unit testing and debugging
- Source control support
Amongst many, a few common Python IDEs include the following:
- Python IDLE installed with Python
- PyScripter
- Commercial systems, such as Wing IDE and PyCharm
- PythonWin
Additional Python references
The information contained here is not a Python language reference. Certain Python syntax and behavior are explained with respect to examples and concepts used to demonstrate how to write a geoprocessing script.
A suitable Python reference book is strongly recommended to augment the information you find here. For Python beginners, Learning Python by Mark Lutz and David Ascher, published by O’Reilly & Associates, and Core Python Programming by Wesley J. Chun, published by Prentice Hall, are both good introductions to the language and are not overwhelming in scope. There are many other books on Python and its particular uses, with new ones being released regularly, so explore what is available. The Python Web site has full documentation for Python, but it is concise and developer oriented. There is a large online Python community with many online resources that are accessible from the Python home page.
If you're new to Python, the external tutorials listed here are recommended for you.
- Python Tutorial is part of Python's own documentation.
- Python for Non-Programmers provides tutorials for those with limited programming experience.
- Python Language Reference describes the syntax and semantics of Python.