Simon Willison’s Weblog

Subscribe

1,023 items tagged “python”

The Python programming language.

2004

Python will assimilate you (via) “From the wind-up school of technology strategizing”

# 8th August 2004, 6:49 pm / python

Backporting from Python 2.3 to Python 2.2

We have a home-grown templating system at work, which I intend to dedicate an entry to some time in the future. We originally wrote it in Python 2.2, but upgraded to Python 2.3 a while ago and have since been evolving our code in that environment. Today I found a need to load the most recent version of our templating system on to a small, long neglected application that had been running the original version ever since it had enough features to be usable.

[... 356 words]

Python in Mathematics

Python in the Mathematics Curriculum by Kirby Urner is something of a sprawling masterpiece. It really comes in four parts: the first is a history of computer science in education, the second an appraisal of the impact of open source on education and the world at last, the third a dive in to the things that make Python so suitable for enhancing the mathematics curriculum and the fourth a discussion of how computer science and traditional mathematics are likely to play off against each other in the field of high school education.

[... 319 words]

PHP 5 Release Candidate 1

I haven’t blogged much about PHP in a while because I’ve been up to my nose in mod_python and loving every minute of it. This news is just too important to miss: PHP 5 Release Candidate 1 has been released, bringing the first production-ready release tantilisingly close. While I doubt PHP 5 will tempt me back it’s definitely an exciting upgrade—my biggest complaint with PHP 4 is the brain-dead object model which defaults to copying whole objects rather than passing references, and this is one of the many things addressed by PHP 5. The new libxml2 powered XML features sound really powerful, and SQLite as an on-board database should be ideal for knocking out small stand-alone applications without needing to set up a mySQL database for them.

[... 173 words]

Ned Batchelder: Showing C header structure. Using Python to maked other languages less painful

# 4th February 2004, 1:19 am / c, ned-batchelder, python

Ned Batchelder: handyxml. Yet another XML object wrapper for Python, this time with full DOM method support included

# 26th January 2004, 2:52 am / xml, python, ned-batchelder

AppScripting (via) The power of AppleScript with the less verbose syntax of Python

# 6th January 2004, 2:12 am / python, applescript

2003

Installing psycopg on Red Hat 9

Adrian Holovaty and I spent some time today figuring out how to get the psycopg Postgres module to install on Red Hat 9. It took a while, but eventually we tweaked the spec file and used it to compile our own RPM. I’ve posted our modified spec file to the psycopg mailing list. More for my own record than anything else, the arcane incantations needed to create the RPM went roughly as follows:

[... 151 words]

Donate to the PSF! Support Python as well.

# 20th December 2003, 10:02 pm / psf, python

Implementing filesystems in Python

LUFS-Python provides a relatively simple API for implementing new Linux filesystems in pure Python. You install the package, write a class implementing methods for handling filesystem operations such as creating a directory, opening/reading/writing/closing a file, creating symlinks etc and finally mount your new filesystem with some special arguments to the mount command.

[... 371 words]

Extracting the length from MP3 files with Python

Ned Batchelder recently wrote about the difficulties involved in extracting the length from an MP3 file. We’re going to need to solve this problem soon at work; luckily, it seems that the answer may lie in the Python bindings for mpgedit, an audio file editing library available for both Windows and Linux.

[... 149 words]

Discovering Berkeley DB

I’m working on a project at the moment which involves exporting a whole bunch of data out of an existing system. The system is written in Perl and uses Berkeley DB files for most of its storage.

[... 339 words]

Numerical Python. Some day I really ought to get this installed and figure it out

# 23rd November 2003, 11:55 pm / numpy, python

Python Natural Language Toolkit (via) Yet another reason Python at University is a great idea

# 23rd November 2003, 11:54 pm / nltk, python

Extracting EXIF data with Python

I’ve been rewriting the photo gallery management system for KUSports.com in Python. One of the new features is that the system can automagically extract caption and photographer information from the photos, provided the information has previously been added to the jpeg file as EXIF data. I tried several methods of doing this but eventually settled on EXIF.py because it worked straight away using a simple process_file() function and doesn’t require any additional software. Recommended.

Optimising Python

Some great tips for optimising Python, courtesy of Ian Bicking:

The difference between POST and GET

How important is the ability to tell the difference between data sent by POST and data sent by GET (i.e in the query string) when developing web applications? Some web frameworks (such as PHP) provide separate mechanisms for accessing POST and GET data. Others (such as Python’s cgi module) provide a single interface to form information that doesn’t distinguish between the two. I already have a strong opinion on this but I’m going to leave it open for discussion here for a bit before weighing in.

Using XPath to mine XHTML

This morning, I finally decided to install libxml2 and see what all the fuss was about, in particular with respect to XPath. What followed is best described as an enlightening experience.

[... 576 words]

The Python Web SIG

Python now has a Web SIG. SIGs are Special Interest Groups, each with a target to develop and improve a certain aspect of the Python language, standard library or community. The Web SIG has two purposes: create a plan for improving Python’s web client abilities (including things like the ability to parse CSS) and work on improving Python’s server side capabilities.

[... 289 words]

“Getting” Python

David Brown: Python is a time bomb (in a good way):

[... 236 words]

Python snippet: ordinalth(n)

Blogged so I don’t lose it (blogging as external memory):

[... 66 words]

PHP’s date() function in Python

In switching from PHP to Python I’m discovering an increasing number of PHP functions that I’ve learnt to rely on but have no direct equivalent in the Python standard library. Often Python simply provides a different way of approaching the problem, but old habits die hard and I’ve been replicating some of PHP’s functionality in Python for my own personal use.

[... 422 words]

Infinite Python Data Structures

Hans Nowak has been churning out some really interesting Python stuff recently. He’s been experimenting with Self style objects in Python (similar in many respects to objects in Javascript), developing Wax, a coder friendly wrapper around wxPython, working on a Python framework for writing text adventure games and most recently experimenting with streams in Python using generators.

[... 168 words]

mod_python introduction

Introducing mod_python by Gregory Trubetskoy. One of my biggest problems with mod_python is that documentation outside of the mod_python manual is pretty hard to come by. This article is more of an executive overview than a tutorial, but anything that adds to the overall body of knowledge out there concerning mod_python has to be a good thing. I’m hoping to write some material on mod_python best practises at some point in the near future, but I have to work out what they are first. Luckily the project has an active and very helpful mailing list.

Dive Into Python reborn

Sweet. Mark Pilgrim is working on Dive Into Python again, funded by a dead tree publisher for publication in 2004 (hopefully). The free version will stay available as well. I’ve always preferred reading paper to reading a screen so I’m definitely down for a copy.

[... 135 words]

“sexeger”[::-1]

Via Ned Batchelder, an article on Reversing Regular Expressions from Perl.com. Otherwise known as Sexeger, these offer a performance boost over normal regular expressions for certain tasks. The basic idea is pretty simple: searching backwards through a string using a regular expression can be a messy business, but by reversing both the string and the expression, running it, then reversing the result far better performance can be achieved (reversing a string is a relatively inexpensive operation). The example code is in Perl, but I couldn’t resist trying it in Python. The challenge is to find the last number occurring in a string.

[... 384 words]

Google conspiracy theories

Microdoc News have a poorly researched story suggesting that Google have been engineering their search results to favour their own properties:

[... 582 words]

Interactive Python

I adore the Python interactive interpreter. I use it for development (it’s amazing how many bugs you can skip by testing your code line by line in the interactive environment), I use it for calculations, but recently I’ve also found myself using it just as a general tool for answering questions.

[... 983 words]

Python for teaching mathematics

Kirby Urner provides some great examples of how Python can be used as an aid to understanding mathematics on the marketing-python mailing list. I particularly liked this demonstration of Pascal’s triangle using Python generators:

[... 139 words]

Python Client Libraries

Three really useful looking Python modules: ClientForm, ClientTable and ClientCookie. ClientForm looks like it provides similar functionality to the form handling part of the WWW::Mechanize perl module, discussed previously. It essentially provides a very simple interface for loading an HTML page, parsing out the form information then filling in the form and submitting it back to the server. The author recommends it for automated testing (I’ve always had trouble figuring out how to link unit testing in to web applications) but I’m sure it could be useful for screen scraping tools as well. ClientTable is an early beta of a powerful looking table parser, and ClientCookie sits on top of the standard urllib library and transparently persists cookies in between requests.