Tuesday 20 October 2009

MacPorts Reference

I use MacPorts to install a lot of development software: latest Python versions, MySQL, MongoDB, etc. And I can never recall the various port commands, so I'm listing the ones I use here:

Update MacPorts: sudo port selfupdate

Search for a port: port search port_name

Install a new port: sudo port install port_name

List a port's variants: sudo port variants port_name

Install a new variant port: sudo port install port_name +variant_name

List installed ports: port installed

List outdated ports: port outdated

Update outdated ports: sudo port install outdated

Clean up temp files: sudo port clean --all installed

Delete old install versions: sudo port -f uninstall inactive

They're the ones I use the most. Anyone suggest others that are handy?

Thursday 8 October 2009

Python through Osmosis

A short note: Python Osmosis is a great video podcast for those who want to learn, or brush up on aspects of, Python. Get it from the website, or subscribe through iTunes.

Saturday 3 October 2009

An Alternative to ElementTree -- lxml

I use ElementTree as my XML library of choice in Python, but sometimes it is lacking in what I need it to do. I have always found its support for namespaces to be awkward to use, and recently I needed to validate generated XML against a collection of XML schemas, but ElementTree has no support for this.

So I had a hunt around and discovered lxml, a Python XML library that -- not only appears to actively developed -- provides good compatibility with ElementTree while layering on additional functionality.

The only downside to lxml is that it requires both libxml2 and libxslt to be installed, though if you install from the binary egg, it includes these libraries, making it very straightforward to run on Windows. On the Mac, you might need to upgrade the libraries, which can be a chore, though using MacPorts makes life easier.