1,155 posts tagged “python”
The Python programming language.
2004
The Observer Pattern in Python (via) Makes smart use of weak references.
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]Switch statements in Python
Python doesn’t support a native switch statement. I’ve found myself using the following coding idiom instead recently which seems to work pretty well:
[... 114 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]Python Cookbook: Parsing the command line (via) Using optparse, but with the command line setup options stored in the program’s docstring.
Panther, Python, and CoreGraphics (via) I didn’t realise Apple shipped special custom Python modules with OS X.
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]Mod_python’s PSP: Python Server Pages. Grisha spills the beans for ONLamp.
Advanced Python network programming
Understanding Network I/O, Part 2 by George Belotsky (via The Farm) is the best tutorial on the subject of network programming I’ve seen yet. It provides a detailed explanation of simple threaded network clients, thread pools using the Queue module and asynchronous I/O using both Twisted and Python’s asyncore library—then discusses the strengths and weaknesses of each approach.
[... 93 words]Code generation vs data driven programming
Via Ned Batchelder, this interview with pragmatic Dave Thomas on code generation closely reflects my own nascent thoughts on the issue:
[... 369 words]Ned Batchelder: Showing C header structure. Using Python to maked other languages less painful
XML.com: Lightweight XML Search Servers [Jan. 21, 2004] (via) More fun with Python and libxml2
Ned Batchelder: handyxml. Yet another XML object wrapper for Python, this time with full DOM method support included
Python Cookbook : FSList (via) A fun alternative to os.path and friends—a list subclass for directory access
AppScripting (via) The power of AppleScript with the less verbose syntax of Python
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]Javascript from Python
In a way I’m disappointed to see python-spidermonkey released. It’s a Python wrapper around the Mozilla project’s SpiderMonkey Javascript engine which allows Python scripts to execute Javascript code in a rock-solid, battle-tested embedded interpreter.
[... 187 words]Donate to the PSF! Support Python as well.
New Python Computer Science text book
Python Programming: An Introduction to Computer Science is a new Computer Science text book designed for use in introduction to programming classes, written by John Zelle, who’s Teaching with Python page . Kirby Urner recently posted a mostly positive review of the book to the Python Edu-SIG mailing list, which sparked an interesting discussion about Python’s place in the CS curriculum.
[... 183 words]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
Python Natural Language Toolkit (via) Yet another reason Python at University is a great idea
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.
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]