Unique chance to see old posters on the Tube

London Underground is undertaking a major transformation of many of its stations, involving retiling walls, relaying floors and generally sprucing things up. This has led, at Euston and other stations, to a surprising revelation. If you’re in the hall which separates the Victoria and Northern Line platforms at Euston, you can see some grubby posters on the wall, some torn some not. If you look closely you’ll see that they’re displaying phone numbers starting 01- and advertising albums which were (just about) fashionable 15 years ago.

The reason is that around the early 1990s, they replaced a number of these on-the-wall advertising spaces by more classy lighted boxes. Only they didn’t strip the existing posters back when they did it; they simply bolted the box on the wall over the top. It means that, as LU take all the fittings off the wall to re-tile, we’re given a glimpse of the adverts of 15 years ago (or less, depending on which station you’re looking at).

Keep an eye out; you might spot something you recognise.

Building the Python trunk with Visual Studio 2008 Express

Thanks to today’s patch by Christian Heimes to the Python trunk, it’s now possible to build Python out-of-the-box using Microsoft’s free [beer] Visual Studio 2008 Express. Whatever your views may be on free compilers and so on, this is great news for MS-types like me. I have effectively no experience using Visual Studio, but I simply did the MS download dance, double-clicked on the .sln file in PCBuild9, selected Release and hit Build. All that remained was to build the few modules which require external code. I didn’t attempt _tkinter, _bsddb or _ssl which are considerably more tricky (and which I never use) but _sqlite3 and bz2 built easily following the README instructions.

Many, many thanks to Christian for making this work. All that remains now is to see if I can build extensions!

Return from Vitoria

Well, I’ve spent the last two days in northern Spain (or southern Euskadi, if you prefer), in Vitoria in the Alaba province, courtesy of the Raices de Europa cultural group. I met one of their organizers over the summer and he invited me to come a give a talk on their two-day (well, two-evening) conference on the Challenge of New Technology.

The people were tremendously welcoming, especially Alberto & Pilar who showed me around Vitoria on the Wednesday morning. Alberto also gave me a lift back to Bilbao airport on the Thursday, and we stopped off on a hilltop to look down into the valley. It was truly magical. The colours were vividly autumnal and, although Alberto was disappointed that a fair amount of billowy-white cloud was obscuring parts of the valley floor, for me it added a kind of fairytale effect to the scene: magical. The weather throughout was bright but cold, not unlike London.

The conference itself went better than I’d expected. There were two speakers each evening, and I was a little overawed to see the eminence of the others: a Professor of something, the head of some Institute, and I was up with the head of Customer Relations of Microsoft, Spain. Fortunately, she turned out to be a charming young Catalan (characteristcally named Montserrat) now living in Bilbao and who speaks English (and French and German!) from having done a business course in Oxford. Her talk was essentially New Technology from the Microsoft perspective, but flavoured with her own reflections, and subtly tailored to the regional organisations who were sponsoring the conference. Mine was a more humanistic and individual call for an equilibrium between the headlong rush into more and more technology and the need to retain a human dimension. More by luck than foreplanning, the two talks complemented each other nicely, and there were some interesting questions from the audience at the end. [*]

In fact, the worst moment of the whole thing was landing back at Heathrow in a tremendous rainstorm. The plane was all over the place; I’ve never been quite so nervous on a flight in my life! But the Iberia pilot took it all in his stride, brought us down smoothly and got a round of applause from the passengers.

I had a fantastic two days over there. The weather was lovely, the way of life charmingly distinctive, people were friendly and engaging. If they invite me again, I’ll be certain to go back.


[*] Including Disgusted of Mondragón who claimed an Imperialist approach (I’m not joking: that was the word he used) by the English Language to dominate the world of IT. Ms Microsoft did make some good points in defence, but was obviously hampered by having to use such phrases as “Office dos-mil-siete” and “pagina web”. I just pointed out that “imperialism” usually implied some kind of intent, while in fact no-one in England (or America) gives a hoot what words people use in other countries for their IT terminology.

Python, Win32 & codecs: the joys of open source

As you may have realised, Windows is my primary development platform. (Truth be told, my sole development platform unless something unexpected comes along). Although I can, technically, write code in C etc. I’ve been spoilt by the sheer quantity and, for the most point, quality of Python libraries which a generous army of itch-scratching developers has seen fit to unleash on the world in the form of precompiled Win32 binaries. So aside from a bit of dabbling, I’ve never really had to compile a Python extension in earnest on Windows.

Until now. I’ve been tasked with producing a program which will scan a batch of media (basically video) files to ascertain whether they meet an agreed reference standard. I’m not a digital media expert as such, but one of our guys who is wrote down the specs I needed to match against, and I went scouting on suitable websites to find the information I needed. Now the first thing I realised is that in the wonderful world of multimedia, one person’s “bitrate” is another person’s “multiplex bitrate” and yet another’s “sample rate”. I’m not saying that these and other terms are interchangeable strictly speaking, merely that they are sometimes used as if they were.

My starting point, given that we’re using an embedded Windows Media Player to play the files out was to automate WMP (via win32com and MPlayer.OCX) because since it could play the files in question it would, ipso facto, be able to tell me whatever I wanted to know about them. At the same time, I assumed that the Property-sheet properties of any of the same files would come from the same source and that as a simple workaround, my users could right-click files to get the information I needed. Wrong on both counts. (Don’t ask why; I’ve no idea. I’m moving too fast at this point to do more than look through the frankly scant information available in the Windows Media SDK).

Absent my primary point of information, my mind moved towards open source libraries. And, obviously, to ffmpeg, the factotum of the open source media world. Naturally, I knew that pymedia was the usual answer to “How do I…?” questions of this sort. Unfortunately, the only Python 2.5 build I could find (from the mailing list) failed to recognise most of the files I had. I did consider building it, but decided to look for a closer-to-the-metal interface to ffmpeg itself.

Which brought me, by way of Pyrex and its fork Cython (I’d no idea how good those were; must try them out as soon as) to AVBin & Pyglet. Together, these came tantalisingly close to giving me what I wanted, but lacked just a few of the attributes I was after. So… a search through the ffmpeg source code and examples later, I had a couple of patches ready for AVBin and Pyglet. [*]

I admit I didn’t go searching the web for COM components or Dlls which promised to return details of media formats. That’s partly because I’d have had to do some plumbing anyway to use them, and partly because — assuming they were closed source — I might well have ended up with the same mixture of information I’d started off with. The open source advantage is that I could go back and back through the code bases of the various projects to find out exactly what information was being returned in each field. The disadvantage for me as a Windows developer who doesn’t usually build Python extensions is that I had to go through the more than slight pain of building an environment in which I could in fact build the extensions (involving MingW, MSys and various build scripts) but I’ll keep that story for another day.


[*] Which were quite rightly rejected by the project maintainer as I hadn’t followed the project standards: let this be a lesson to all you young coders out there!

sqlalchemy 0.4 is out

For those who hadn’t seen the announcement, the sqlalchemy team has released v0.4 (they don’t believe in big version numbers, do they?). I mentioned previously that they seem to be doing good things, and I’m really looking forward to having another bash at it this time round.

The main thing, though, is that they’ve really put a lot of effort into the docs. They’ve not just added new features; they’ve produced a sort of front page with lots of useful links, and the docs themselves are up to scratch. If I do have a grumble, it’s the same grumble you have with any many-layered software: there’s more than one way to do it, and it’s not clear at first which way you should go.

Great work from the sqlalchemy team!

To genexp or not to genexp - a cautionary tale

I don’t know about you but I’ve been increasingly comfortable using a genexp style when passing sequences as parameters. It just saves a bit of syntax clutter and generally does exactly what you want. To give a completely trivial example:

a = range (10)
print sorted (i for i in a if i < 7)

But (there’s always a But) I found myself having unexpected problems with a database-row class I’d recently beefed up and I couldn’t work out why. It’s one of these things I’m sure everyone’s done where you pass it the cursor description and the row values and it does the __getattr__ and __getitem__ stuff for you. Well, it was acting as though the cursor wasn’t passing the column names at all. I suspected the new(ish) version of pyodbc I’d installed lately, but it was soon clear that the problem was in the generated Row class itself.

Of course, it turned out that I was, as above, passing the column names as a genexp. And some early reference was consuming the generator, silently leaving nothing for a later reference to consume. Something like this:

q.execute ("SELECT blah FROM blah")
Row = row.Row (d[0] for d in q.description)
return [Row (i) for i in q.fetchall ()]

where the code in row.Row did something like this:

def Row (names):
  something = "-".join (names)
  ## Oops, consumed the generator
  description = dict ((name, index) for index, name in enumerate (names))
  ## Oh dear, nothing left to consume but not an error

You see that I’m not falling into the trap of returning the list of rows as a genexp, because I know I’m likely to be using it in several places, but it’s just that bit cleaner to pass as a genexp as a parameter, and I fell for it.

One more thing to look out for.

Wherefore art thou misquoting?

Not really a misquote, since the quote itself is generally perfectly accurate (mutatis mutandis). Rather a misunderstanding of what the quote means. In my experience, nine out of ten people who say “Wherefore art thou, Fred?” think that they are using some sort of Shakespeare-speak for “Where are you, Fred?” and completely miss the point that “wherefore?” means “why?”. Juliet is not asking “Where are you Romeo?” but rather “Why are you Romeo?” … and not someone else with whose family my own family is not at daggers drawn.

Python mailing list and the Mr Men

I don’t know if it ever made it outside the UK, but there was a very popular series of books when I was a kid called “The Mr Men”. They were written and illustrated by Roger Hargreaves, were about 6″ square and each book was the mini-story of a Mr Grumpy or a Mr Happy or a Mr Small etc. They became a television series narrated by Arthur Lowe (of Dad’s Army fame) and most people of my generation can still hum the theme tune. (Dum dum-de-dum-de-dum-de Dum dum dum dum…). There was a later follow-on series called the Little Misses which I don’t think did quite so well.

Well the point of this trip down Memory Lane is that you see many of these same characters go by if you watch the Python mailing list. Python’s is the widest ranging of the technical mailing lists I subscribe to: I don’t follow the less focused Linux or Windows lists and the others I do subscribe to are mostly project-based (Pyro, cherrypy etc.). I’ve followed and contributed to the Python lists for several years now and amusedly watched the self-same questions and ideas come and go more than once. As I write there’s a thread about using regexes to validate email addresses and another about address-line recognition. A few months ago I remember someone posting in mock concern that we’d got to the middle of the week without someone asking whether the self parameter to class methods couldn’t be determined automatically (or some other such FAQ).

But the thing I most want to say is that I have learnt so much from reading the posts on the Python list. Learnt both from the point of view of technical and other knowledge and from the point of view of how people are and how they work and how they act and react differently. On the merely technical front, obviously I pick up new information when someone suggests a technique or a module I was unaware of. The same thing happens when someone asks a question I feel intrigued enough to attempt even when I don’t know the answer straight off. (Usually something Windows-y). But outside those, there are the kind of threads which spin off on tangents — not infrequently to the bewilderment of the poor bugger who just wanted to know whether Python’s datetime module handled leap-years or something. It’s there that you benefit from the wide reach of Python to people for whom programming is not the be-all-and-end-all of life. I’m sure it annoys some people who want their tech served neat, but I enjoy the maverick threads which diverge into language pronunciation, mick-taking of blatant spam attempts, and even those top-posting ding-dongs that always seem to come up.

Over and above all that, there’s the people - the Mr Men because, let’s face it, they mostly are Mr Men. There are fiery radicals, meek newbies, young racers champing at the bit, wannabe script kiddies, old hands, new faces, hardy perennials and seasonal bloomers. There are people who excel at putting others’ backs up, and people who calm things down. There are people who post their entire program, and those who put their entire question in the subject line. There are top-posters and bottom-posters, Usenet diehards and Web-forum youngsters.

The thing which never ceases to impress me, though, is when people are big enough to back down and say Sorry. There was a post recently which got quite heated and I though would end up in a heap on the floor. But the OP, and principal defendant so to speak, realised he was wrong, cooled off and offered an apology to the list. Good for him (I’m assuming it was a him).

Maybe one day I’ll grow tired of it, but for now I enjoy the virtual community. I imagine the communal groan when someone asks “What’s the best editor/framework?” or “How do I do private attributes, since they’re an undeniable part of Object-oriented programming?”; I give a small cheer as Python is seen to be behind some well-known or highly-feted website; and I look forward to the Quote of the Week.

Python London meetup 10th Oct

A good turnout yesterday for the first of what Simon described as “the formal London Python meetups” — formal because at the Thoughtworks offices with some presentations. I was on first, talking about the Windows-specific WMI to an audience consisting almost entirely of *nix Pythoneers! (Went ok, despite my setting my font size too large and not realising that I could pick up my laptop and face the audience).

Chris Miles followed with his PSI lightning talk. Then we were back to Windows again for a double-whammy from the Resolver folks. First their head-honcho Giles gave an amusing view of the ups-and-downs they’ve suffered (all, I might add, within a general trend of success). And then Michael Foord gave some impressive demos of IronPython running under SilverLight within a browser.

All in all, I’m really looking forward to another one. And many thanks to Simon for organising and Thoughtworks for paying for the pizza — at least I hope they did because no-one asked me for any dosh!

Two more How-Do-I entries for shell shortcuts

(I’m just picking the low-hanging fruit here before girding my loins and plunging in to the deep waters of Shell extensions!). Just added two more How-do-I entries, one for general shortcuts, the other for the URL shortcuts. (Although I’m not entirely sure what you achieve with a URL shortcut that you don’t achieve with a normal shortcut that has a URL target). You can find them and the other entries on my Win32-How-do-I pages.