Python Programming, news on the Voidspace Python Projects and all things techie.

IronPython News

emoticon:pda Well it's finally happened, IronPython is now Live on Codeplex. Smile

Perhaps even more interesting is that Sanghyeon Seo is working on :

The ctypes port is relatively straightforward [1]. Of CPython Reflector, Sanghyeon says :

When finished, this should allow importing CPython native modules in IronPython.

This is very cool. Cool

[1]Well, you know what I mean...

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-09 21:38:42 | |

Categories: ,

Writing CGI Programs, Part II

emoticon:pen_book A while ago I wrote a two part series [1] on Writing CGI Applications with Python, for PyZine.

They published the first part in issue 8 (free to read) :

Writing Web Applications as CGI - Part One [2]

Unfortunately since then PyZine has ground to a halt, so they have given me permission to publish part II here on Voidspace :

Writing Web Applications as CGI - Part Two

CGI programs are very easy to write, and can be the simplest (or only on some hosting accounts) way of delivering dynamic content using Python. These articles introduce you to the subject, and give you a good start writing your own scripts. No AJAX though. Wink

[1]Or at least a two part introduction to the subject. Smile
[2]Part II uses functions defined in part I. PyZine is sometimes offline. You can usually find a google cache at Cached Version of Part I

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-08 23:02:59 | |

Categories: , ,

Ajax in Action, Review

emoticon:avocado Ajax in Action is another of the Manning In Action series. It weighs in at a mere 650 pages, and is written by David Crane, Eric Pascarello and Darren James.

I guess most people reading this blog will know about AJAX. For those who don't, AJAX stands for Asynchronous Javascript And XML. This is a bit of a misnomer as it needn't be javascript [1], it needn't involve XML, and there are synchronous techniques as well as asynchronous. Smile

That aside, AJAX is a useful word to describe a set of web programming practises. These were popularised around early 2005 by applications like gmail and google maps [2]. Since then everyone is doing it. AJAX uses web technologies that have been available for quite a while. It solves the problem with 'normal' web applications, that every action forces the whole page to reload whilst the information is pushed to the server and a new page returned. This makes using 'non-AJAXy' web applications a slow and frustrating experience.

AJAX uses a Javascript function XMLHTTPRequestObject to get (or POST) smaller pieces of information from a server in the background (asynchronously). Your application can dynamically alter the DOM [3] depending on the result. Whilst this is happening the user can continue to use your application.

This means that it is possible to write browser application that are almost as responsive as traditional rich client GUI ones. When a user does something, the browser can exchange smaller amounts of information with the server, and only alter part of the page.

Web applications have their own particular set of problems though. Not least of these is the different behaviour and bugs in the different browsers. As well as this, AJAX techniques can break the users expected behaviour of bookmarking and the back button. This is because a user's actions don't automatically change the URL.

This book starts (as you might imagine) with an introduction to AJAX and web programming technology. It is very well written and easy to follow, and outlines the workflow of a traditional web application and an AJAX web application. It draws a distinction between transient applications, which the user uses intermittently within their workflow, and sovereign applications which a user may focus their attention on for hours at a time.


This is why tabbed browsing in browsers like Firefox is so much more bearable. Whilst one page is loading you flick to another tab. Each page only holds your attention transiently.

The book points out that for transient activities an interrupted workflow is acceptable. For a sovereign application, significant pauses in the workflow will seriously frustrate the user.

The traditional model of the web has been based on the fundamental concept of the webpage. It is this break whilst pages reload that has made the web unsuitable for delivering sovereign applications. AJAX removes the concept of the individual page altogether. It restores the browser to being a user interface to a full (clientside) application, which just makes calls to the server when necessary. This makes a rich and responsive UI a possibility. To do this requires a complete rethink of web design.

We've set a goal for ourselves... of delivering sovereign applications through a web browser, thereby satisfying the goals of user productivity, networking and effortless, centralized maintenance of an application all at once. [4]

So programming in javascript is no longer about scripting web pages, but designing and implementing full applications.

As Ajax in Action proceeds it not only explains and illustrates the technologies, but also focusses on how to bring good programming practise (design patterns, MVC, code reuse, refactoring etc) to your application.

This is one of the best programming books I've read. It is easy to read whilst retaining a reasonable density of technical information and plentiful examples. It doesn't require anything greater than a passing familiarity with Javascript to be able to understand the examples, but a general understanding of programming is required.

It covers a wide range of advanced aspects of UI design with AJAX and different client-server interaction models. It also mentions (and uses) several of the popular AJAX toolkits available. My only issues with the book are the lack of Python examples on the server side, and that MochiKit gets little but a passing mention. Wink

[1]It probably will be javascript, but client-side scripting can be done in VBscript or (theoretically at least) almost any language of your choice.
[2]The term AJAX is generally credited to Jesse James Garrett of Adaptive Path.
[3]The whole layout of the page, including forms and buttons can be altered from Javascript.
[4]Page 29. Razz

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-08 10:13:41 | |

Categories: ,

ConfigObj Stuff

emoticon:eggs ConfigObj 4.3.2 had over two hundred downloads in the first forty-eight hours. That's nice. Razz

Also it looks like ConfigObj 4.3.1 got turned into a debian package only hours before I released 4.3.2. Laughing

More importantly, there are now eggs up on the cheeseshop, so Turbogears users (and anyone else) should be able to install ConfigObj using setuptools. These eggs also contain validate.

The current release should address the issues in this Turbogears ticket.

There are two proposals to improve string substitution [1] in ConfigObj.

The first is to allow PEP 292 string substitution.

Currently ConfigObj uses ConfigParser style interpolation :

foodir = %(something)s
foodir = %(dir)s/whatever

PEP 292 (along with lots of other languages) uses :

foodir = $something
foodir = ${something}/whatever

This is much better, but for backwards compatibility the ConfigParser style substitution would need to be the default. The interpolation option would then need to have several options :

  • True - ConfigParser style
  • False - off
  • ConfigParser - guess Smile
  • Template - PEP 292 style

This is more complicated than it was. Confused

Everyone who has commented on this has said that it is a good idea, so this will probably make its way into the next version of ConfigObj. Many thanks to Robin Munn for the suggestion, code and documentation. It does leave an issue of recursive interpolation and $$ which is used in PEP 292 substitution to escape the $ sign. Maybe I should just get rid of recursive interpolation ?

The second change is slightly more controversial. Currently ConfigObj does interpolation from the DEFAULT section of the current section, parent section or root section.

A couple of users have suggested that using the current section first would be better ? This could break backwards incompatibility, but as I don't use string substitution at all it doesn't affect me. Anyone else got any thoughts ?

[1]Also called interpolation.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-07 23:55:52 | |

Categories: ,

Firedrop2 Bookmarklet

emoticon:cat A little extra to go with the new release. Davy Mitchell has created a fantastic little bookmarklet for Firedrop2.

Drag the Firedrop2 Blog This! link to your bookmarks.

When you activate this bookmark, with text selected on a page, a new window will pop-up with your selected text in it, and a link in ReST format. Cool

Very cool. I'm sure we can smooth out some very rough edges, but I like this a lot.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-07 22:32:53 | |

Categories: , ,

Firedrop 0.2.2

emoticon:firedrop2 Firedrop 2 0.2.2 is now available. Cool

You can download it from :

This is an important release with several new features, and contributions from new developers joining the team.

What is Firedrop2 ?

Firedrop2 is a free, cross-platform blogging tool written in Python. It keeps your blog source files on your computer, making it a clientside tool. This means you control your blog, and can easily move it from one server to another, with no risk of losing data. It also means you can manage your blog offline. Cool

It is fully open source, and has all the features you expect from a modern blogging program :

  • RSS feed generation
  • Categories
  • Automatic archive generation
  • A powerful set of plugins, including spellchecker, emailer, and themes
  • Entries can be made in text, HTML, ReST, textile, sextile or markdown markup
  • HTML templating system and macros for all sorts of tricks
  • Built-in FTP capability for uploading your blog to a server
  • Integrated blog comments support (Through Haloscan)
  • Because it's written in Python, it is easy to extend Firedrop or create new plugins for it

What's New ?

This release has a lot of bugfixes and changes. Hopefully I've remembered the important ones. Smile

  • Fixed a bug with categories and the unicode wxPython
  • Added the Themes plugin by Stewart Midwinter [1]
  • RSS feeds can be generated for all the categories, by Davy Mitchell
  • Firedrop now saves user data in the users home (checking sensibly for directories where it has write permissions)
  • Now includes support for the Haloscan comments system.
  • Addition of the Firedrop2 banner by Stewart Midwinter.

Plus other code improvements and bug fixes.

Their is already work being done on the next release. This will include features like :

  • Faster build time through entry HTML caching
  • Blog statistics report generation
  • Tagging
  • A Podcast plugin
  • Extension to the plugin protocol for extra plugin capabilities
[1]The Themes plugin requires version 0.3.32 of Wax, or more recent.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-07 21:53:24 | |

Categories: ,

Python for my Grandpa

emoticon:baldguy Now that I am employed as a Python programmer, my Grandpa wants to know what I get up to. He is nearly 80, and very intelligent. He can now send email, but as far as computers go; that's about his limit [1].

He recently asked me :

What is the fundamental and essential difference between "PYTHON" and, say, the program language used for MS Windows.

I'm looking for a half page explanation that I can grasp...

This was my reply, which unfortunately spans a bit more than half a page. Razz

You're actually asking a difficult question. The usual answer only takes a few lines, but each line contains several concepts that themselves require half a page of explanation.

I will try to explain it with as little "jargon" as possible.

First the one line summary (this does include jargon) ! :

Python is a high level, interpreted, cross platform, dynamic language. It has an emphasis on readability and expressiveness.

Windows is probably written in a combination of two languages which are similar to each other : C and C++.

These are all low level, statically typed, compiled languages, that are difficult to read !

Now a better explanation ! (Sorry - too many exclamation marks, I will try to cut down.)

In order to write programs like Windows you need complete control over everything the computer does. This means that you need to do every little task manually. Languages that do this are called low level languages. The program you write then goes through a phase called "compilation", which turns your code into an "executable" which will run only on the sort of machines the compiler is designed for.

Python is a high level language, a lot of the basic tasks are handled for you. This means that it is easier to learn, and also that you can achieve things with a lot less code. Because of this you can write programs in Python a lot quicker than in low level languages.

Python is interpreted, meaning it runs a bit slower than compiled languages. It does mean that you don't have to compile programs in order to run them. (This is important when developing, because to test compiled programs you may have to wait half an hour after making a change before you can test it). It also means that a Python program will run unchanged on lots of different "platforms" - not just computers running windows. Compiled languages have to compile a different version for every target "platform".

The main thing is that Python emphasises a clean and readable style, and that it is very expressive - it is easy to express your ideas in terms of code. That is why I like it.

I won't even attempt to explain the difference between static typing and dynamic typing ! (It is very difficult for a low level language to have dynamic typing, another reason for choosing a high level language.)

[1]He knows a lot about commercial plant and machinery valuation though. Smile

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-06 15:04:41 | |


Vista & Python Executables

emoticon:bluetooth I use Py2exe to create standalone executable programs. Occasionally I use Inno Setup [1] to create windows installers for these programs. One example of such a program is Nanagram the anagram creator.

I recently read Visual Tour: 20 Things You Won't Like About Windows Vista. This is an interesting tour of some of the problems with the beta version of Windows Vista. I'm sure Microsoft will deal with some of these issues, that isn't what this post is about.

Page 4 of this article (the page linked to above) describes one part of the increased security model in Windows Vista :

The third added step is more protection for the System Registry and Program Files folders to prevent applications from writing without permission to the Registry or writing settings data into Program Files folders.


And to be fair, Microsoft has asked software makers for years not to write settings data to the Program Files area...

I didn't know this (having developed as a single user under Windows XP with a security model loose enough to allow you to write virtually anywhere). This means that Nanagram - and any other program I've created installers for - will fail under Windows Vista. When developing I almost always use the program directory for storing program data, when installed this will be in the Program Files folder.

The correct solution (of course) is to use the home directory, creating an application specific file or directory there. For other ignorant Windoze users, the way to find this in Python is trivially easy :

home = os.path.expanduser('~')



A couple of commenters on this entry have suggested alternative ways to find the right place to put application data.

Phillip J. Eby says that for NT [2] the best way is to use :


This gives you the location of the Application Data directory rather than the user's home directory.

Robert O'Connor says that on recent versions of wxPython you can use :


This has the advantage of being cross platform, but is only available if you are using wxPython.

[1]Which is very good.
[2]Windows XP and Windows 2000 are both NT based.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-05 14:41:15 | |

Categories: , ,

Python Scoping

emoticon:boxing_gloves Here's an interesting bug situation I'd not seen before.

Can you tell what exception the following code will raise, and why ?


The clue is in the title of this entry.

def findMinimum(values):
    somevalue = min(values)

    ... # more code

    min = do_something(somevalue)
    return min

print findMinimum([1, 2 ,3 , 4])

Of course the code can be better written. It's a simplest case that illustrates the problem.

The answer to this will probably be obvious to anyone with some Python experience, but it's certainly unintuitive and a confusing error for newcomers.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-05 14:35:06 | |

Categories: ,

ConfigObj 4.3.2

emoticon:file1 ConfigObj 4.3.2 has just been released.

You can download it from

ConfigObj is a config file reader and writer (an ini file round tripper). It has many features, but the main one is that it is simple to use. Its features include :

  • Nested sections (subsections), to any level

  • List values

  • Multiple line values

  • String interpolation (substitution)

  • Integrated with a powerful validation system

    • including automatic type checking/conversion
    • repeated sections
    • and allowing default values
  • All comments in the file are preserved

  • The order of keys/sections is preserved

  • No external dependencies

  • Full Unicode support

  • A powerful unrepr mode for storing basic datatypes

This is a bugfix and minor feature enhancement release. There is a bugfix in unrepr mode, and exception handling has been improved.

The full changelog is :

Changed error handling, if parsing finds a single error then that error will be re-raised. That error will still have an errors and a config attribute. That means the error will be more comprehensible.

Fixed bug where '\n' terminated files could be truncated.

Bugfix in unrepr mode, it couldn't handle '#' in values. (Thanks to Philippe Normand for the report.)

As a consequence of this fix, ConfigObj doesn't now keep inline comments in unrepr mode. This is because the parser in the compiler package doesn't keep comments. Smile

Error messages are now more useful. They tell you the number of parsing errors and the line number of the first error. (In the case of multiple errors.)

Line numbers in exceptions now start at 1, not 0.

Errors in unrepr mode are now handled the same way as in the normal mode. The errors stored will be an UnreprError.

There is also a proposal to support PEP 292 string substitution (which is much better). This will be the target of the next release of ConfigObj.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-04 23:27:46 | |

Categories: ,

IronPython & Windows Forms, Part V


This article has moved.

You can find the whole tutorial series at IronPython & Windows Forms.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-04 08:27:50 | |

Categories: , ,

IronPython & Windows Forms, Part IV


This article has moved.

You can find the whole tutorial series at IronPython & Windows Forms.

Like this post? Digg it or it.

Posted by Fuzzyman on 2006-06-03 01:05:09 | |

Categories: , ,

Hosted by Webfaction