Chapter 1 Introduction To Python
Chapter 1 Introduction To Python
Programming Languages
CHAPTER 1
Introduction to Python
• Python is a high-level programming language
• Open source and community driven
• “Batteries Included”
– a standard distribution includes many modules
• Dynamic typed
• Source can be compiled or run just-in-time
• Similar to perl, tcl, ruby
Why Python?
• Unlike AML and Avenue, there is a considerable
base of developers already using the language
• “Tried and true” language that has been in de-
velopment since 1991
• Can interface with the Component Object Model
(COM) used by Windows
• Can interface with Open Source GIS toolsets
Why not Visual Basic?
• Visual Basic is still the method of configuring
and customizing ArcMap
• If you have a button on the toolbar, it’s VB
• Python scripts can be placed in ArcToolbox
• Python can be run from the command line
without ArcMap or ArcCatalog being open
• Using just the GIS Engine, lower overhead
• Rapid prototyping, ease of authoring, etc.
Python Interfaces
• IDLE – a cross-platform Python development
environment
• PythonWin – a Windows only interface to
Python
• Python Shell – running 'python' from the
Command Line opens this interactive shell
• For the exercises, we'll use IDLE, but you can
try them all and pick a favorite
IDLE – Development
Environment
• Hello World
print “hello world”
• Prints hello world to standard out
• Open IDLE and try it out yourself
• Follow along using IDLE
More than just printing
• Python is an object oriented language
• Practically everything can be treated
as an object
• “hello world” is a string
• Strings, as objects, have methods
that return the result of a function on
the string
String Methods