Python

From Wildsong
Jump to navigationJump to search

A few random notes on Python

About this page

I am using Python mostly for ESRI Geoprocessing. As I become more comfortable with it I am starting to branch out and use it for other things.

This page is not intended as a tutorial or repository of all Python knowledge. It contains random notes on how I am using Python and will change as I learn what works and does not work for me.

IDE

Komodo

I use ActiveState Komodo 4.x, which is not free but I think it's worth it. I think it's about $300. That is for a 'personal' license which means I have permission to install it on all my computers. I admire this approach - I only use one computer at a time. For free, they have a stunted editor "Open Komodo" but I need the debugger.

If you try the eval version you won't want to go back to PythonWin.

Eclipse

I looked at Eclipse for Python but it looked too rudimentary for a beginner. SWT is the widget set used in Eclipse, I am not sure if there are Python bindings for it. It might be a reason to delve into it further. If you are a Java programmer already using Eclipse that might also be a reason to try it with Python.

For the time being though I have made my pact with Komodo.

GUI

So far I have used Python for scripting operations such as geoprocessing. Now I am at the stage where I want to start designing GUI based applications especially ones that can be portable between Windows and Linux.

I want a nice tool to help me design the UI. Therefore I am looking at the following.

wxWindows http://wxwindows.org/ a portable GUI platform for forms based on GTK

wxWidgets http://wxwidgets.org/ the widgets used by wxWindows.

Some relevant Ubuntu packages

boa-constructor RAD tool http://boa-constructor.sourceforge.net/ (Application runs under Linux and Windows)

python-card GUI construction framework http://pythoncard.sourceforge.net/

python-wxglade GUI designer

python-wxtools

python-wxversion

Databases

From the ArcGIS perspective, I can access geodatabases using ArcObjects but for the frequent occasions when it runs out of gas, I can tap into the underlying databases.

For shapefiles I can use dbfpy to read and write the attributes, which are stored in the .dbf file.

For personal geodatabases I can tap into the MDB using either ODBC or OLEDB. See Accessing Personal Geodatabases with Python

For file geodatabases... well, ESRI has not released specs yet so I use PGDB's.

Geoprocessing

ESRI

See also Model Builder

31-Dec-2007 update: ArcGIS Desktop 9.3 includes a new python wrapper module that makes working with ArcObjects a lot easier. I am using ActiveState 2.4.3 with it with good results. It breaks if you try to move up to 2.5.1.

You now just use the python line "import arcgisscripting" instead of directly invoking the COM dispatch thing.

Old notes:

This guy seems to have slogged through a lot of development with it and collected useful notes: http://www.ollivier.co.nz/support/python.shtm

I can add a new one to his list. I was getting error messages on setting gp.workspace = 'foo' where foo is a valid path. It's because the gp object was hanging around in pythonwin's memory. You should be able to say 'del gp' but I gave up and restarted pythonwin to fix it.

When working with ArcToolbox 9.1 and Python 2.1 I have been having lots of crashes in PythonWin. Using it on a computer with ActiveState 2.4.3 I have not been experiencing the same problems. I am going to try installing 2.4x without removing 2.1 so I can fall back on it... I followed the instructions above.

It still crashes. Oh joy. It does not even crash faster.

Open source

How about geoprocessing with OGR/GDAL? Will that do it for me?

Getting Python 2.4 and GDAL without disrupting the ESRI installation... See also Howard Butler's site.

FWtools installs a GUI called OpenEV_FW and a shell environment. It comes with python 2.3.4 which is old. I think Frank does this because it's stable and test with his tools. Going to a newer version means the DLL won't work so you'd need to compile your own.

23-Aug-2006 Python+OGR probably not worth messing with right now. From the OGR site: The Python API isn't really well documented at this time, but parallels the C/C++ APIs. The interface classes can be browsed in the pymod/ogr.py (simple features) and pymod/osr.py (coordinate systems) python modules. The pymod/samples/assemblepoly.py sample script is one demonstration of using the python API.

External Links

dbfpy for accessing .dbf files

Python on Windows CE (and Pocket PC)

Links into official python docs

TUTORIAL http://docs.python.org/tut/tut.html

GENERAL http://docs.python.org/

STRINGS http://docs.python.org/lib/string-methods.html

http://diveintopython.org/