What do we use Python for at work?

Not uncommonly, I suspect, Python was introduced here at work in stealth mode: it wasn’t on the list of products starting with “MS” which we genreally use, but it got the job done and the management has been pragmatic enough to accept its use to the extent that it’s now installed on the baseline image for company PCs and laptops.

So what do we do with it? Well, a surprising amount when I start to enumerate it. As is often the case, quite a few of the uses are of the “glue” style: creating an easy bridge between two other pieces of software, one of which is often the operating system. As an example I years ago wrote a (tiny) piece of code to enumerate the installed printers and pipe them out to a file. Our in-house business app calls the Python and picks up the result to display to the user as a pick list. That’s just one example among many others, some of which are so small that I tend to forget that they exist until some bizarre corner case arises which means I have to revisit the code. They just work and go on working.

A by no means exhaustive list of Python Pieces off the top of my head:

* That list of printers
* The startup wrapper for our main business app
* sql2xl — provider of data to the masses (and indirectly responsible for a world of Frankensheets, I’m afraid).
* Sales Boards - our Pygame-driven availability-visualisation app
* reports - a compact module combining simple dialogs and sql2xl
* screengrabber - capture parts of the screen to save to the database
* imageviewer - simple pygame-based image display
* convert images provided by our customers to thumbnails and place them on a replicating database for our handheld scanners
* convert a batch of Word docs to PDF & PCL
* simple manipulation of DXF maps to add our internal site ids
* absolutely loads of occasional AD / filesystem / WMI scripts for the sysadmins
* the internal contacts / portraits webpage
* web-based password reset for our HR system
* web front-end, mail ingest and alerting (a la Roundup, I admit) for our Helpdesk system

.. and a whole slew of other stuff which pretty much exists to demonstrate just how versatile Python is :)

Breathing life into the active_directory module

For a long time I’ve not been able to give my active_directory module the attention it’s needed, in spite of several people helpfully providing patches to, eg, escape slashes in monikers, bind to the Global Catalog and do other useful things. However… the need to do various things with it at work plus some questions from interested users has resulted in a flurry of housekeeping and — hopefully — improvements. It’s not done yet but, assuming I can sustain the effort, you should see the result in a few days time.

As with much of my stuff, the functionality I implement and the time I spend on it is largely a function of what the sysadmins here at work want me to for them (and how much else I can squeeze in at the same time). Just at the moment there are several initiatives to claw back wasted disc space and do other housekeeping exercises. So I get to allocate some time to my projects. Let’s see how long it lasts…

pycon as seen from across the Tweet

That was an interesting experience: I (re)started using Twitter a couple of weeks ago, for no particular reason except that it seemed to be an increasingly significant backchannel of information around Python, meaning that useful information passes through it which is then assumed or referred to in other forums [*] such as the Python mailing lists or people’s blog posts.

But by fortunate coincidence that meant that I was able to watch the #pycon Twitter stream and get a more immediate flavour of the conference than I would have by following later blog posts. Obviously it was quite fun watching people try to get their questions on the screen for Guido’s keynote speech (took me a while to realise what was going on…).

Throughout the conference you get a mixture of the very immediate (”Has anyone got a Mac VGA Adapter for Room C?”), the impending (”BoF Session for Ruby Enthusiasts in the downstairs toilets”), the infinitely retweeted (”Unladen Swallow….”), the humorously overheard (”OH: OK; Yak shaved”), the running-joke (”Bring goat food to the Testing Sprint”), the contentious (”We were more diverse…”), the you-had-to-be-there (”Looks like @djangopony was left unattended”), the gratitude (”Thanks to everyone…”) and of course the plain exhausted (”Back home now after #pycon”).

I obviously didn’t follow everything in real time, not least because of the time difference: I do have other things to do with my time :) But it was enjoyable watching other people enjoy themselves and feeling at least a spectator to an Occasion in the Python year. Now all I’ve got to do is find time to catch up with slides, video presentations, and A Little Bit of Python.

[*] Note to pedants: seems to me that “forum” has become an English word by adoption which means that you can justifiably form its plural by adding an “s”. If I were talking about meeting places of the Ancient World I might argue for the more classical “fora”.

Sister Eileen Hewlett RIP

My great-aunt Eileen died in November 2009 at the respectable age of nearly 87. Last night, a memorial Mass was held for her at the La Retraite school in Clapham, one of the several schools in London and in Somerset where she’d been involved for many years: as a teacher, as a deputy head or head, as clerk to the governors and as a Sister at the neighbouring La Retraite community.

She was one of those many, many women and men whose lives are lived in cheerful and unnoticed service to many others. In her case, it was in the field of education; she worked in La Retraite schools in London and Somerset all her adult life. (And, indeed, was a pupil at them when younger). I only knew her as a relative; it was wonderful last night and in November at her funeral to meet many of the people who’d known her as a friend, a colleague, and a staunch support of the schools she was involved in.

In this internet age we’re used to finding important or influential people as links on the web, pages in Wikipedia and so on. Just for the sake of it, I stuck Auntie Eileen’s name into Google and found only a reference to her funeral in a parish newsletter. Yet she — and I’m sure many others whom I don’t know — have been so very important in their small communities. When not in Clapham, she lived, worked, and finally died in Burnham-on-Sea, an insignificant seaside town on the Bristol Channel eclipsed by its slightly more famous neighbour Weston-super-Mare, where she started her work as a teacher. Her congregation set up and ran a primary school in Burnham for local children and a boarding school for girls. The boarding school closed 25 years ago and became the residential care home for the elderly in which she spent her final years. She was head of the primary school for some years and many people there will have known her and will remember the crisp precision of her speech and the warmth of her welcome.

She suffered a condition for much of her later life which made walking difficult and finally impossible. But her mind was active right up until the double stroke from which she never recovered. Until the last few years of her life she was indefatigable in her habitual help of the educational communities she served. She would drive (atrociously!) enormous distances to attend governors and policy meetings, and had an acute awareness of modern employment and education legislation which often surprised people who imagined that an elderly nun would have a somewhat backwards viewpoint!

The passing of anyone is a grief to their friends and relatives. As a Catholic myself I believe, as she did, that we will meet again in the next life. But it’s arguably as important to recognise the good which so many people do in their quiet way while they’re still with us: the children they educate; the advice they give; the stand they make in defence of something they hold dear. It was wonderful to meet all Auntie Eileen’s former colleagues at the schools she helped for so long and to hear their stories of how she’d affected so many lives.

Eileen Hewlett 1922 - 2009 RIP

Another Day, Another Dojo

My first Dojo of 2010 yesterday, as I missed the January one (which is a shame as it sounded like fun). This was a return to the conventional Dojo style with pair-programming at the front, the task being to merge the Adventure Game efforts from the previous month’s team-by-team effort. But first, a commercial break… Jonathan Hartley advertised the upcoming PyWeek competition and demonstrated his team’s previous effort as well as the amusingly literal Murder of Crows entry.

Meanwhile, back at the Dojo… Nicholas started off partly to set things up for people (like me, his co-pilot) who hadn’t been there the month before. As we moved through the programming pairs, we did manage to get a working codeset together by merging the location-parsing code from one team with the cmd-based loop from another. But it was clear that things were moving slowly and that the audience was somewhat disengaged…

So we finished off with a broad discussion of ways ahead, of what might work better, and of whether the artificial nature of the Dojo setting meant that people couldn’t “show off”, so to speak, their natural coding style — and ability. Michael G and others made a few cogent suggestions to the effect that smaller teams would work better but with some kind of DVCS (git seemed to be the front-runner) to assist the teams in collaborating. And it seemed that at least one team should be creatives, rather than coders.

I enjoyed it, as ever, but it _is_ difficult to keep 20+ people in a medium-sized room totally engaged. Even with the best will in the world, it’s hard to read code on a screen from some distance back. This was one of the reasons why a team-based approach met with broad approval. Also it is a little dispiriting when you’re doing your best up front but half your “audience” is otherwise engaged.

The point about how “natural” you should be in the Dojo was interesting. Everyone has a different way of coding, of approaching a problem, of looking for information and so on. Dave[*], the last pilot, mentioned that he’d normally take much longer sizing a problem up but that having a time limit forced him into action sooner. But you’re up there with a limit of 10 minutes, probably on someone else’s machine, maybe on an “alien” operating system. You’re fumbling with running up a command prompt; you’re not sure how to bring up the Python docs; the keyboard shortcuts which your fingers remember don’t work — or worse, do something else entirely! We did discuss each person bringing up his own laptop, although that has obvious drawbacks of getting the projector to switch smoothly and so on. It was out of this discussion that the move towards a team-based approach next time arose.

TJG

[*] Dave, incidentally, was the programmer of the BBC version of the Graphics Adventure Creator — did you know that?

Usefulness of itertools.cycle & re.sub

(… or at least the concept). I wanted to process a piece of plain text which would include conventional double-quote marks in such a way that they became HTML smart quote characters (&ldquot; &rdquot;). I was prepared to adopt a naive algorithm which assumed that alternate quotes would always match up, something which obviously wouldn’t work for single quotes. I toyed with various ways of splitting the text up and joining it back together until I came across the slick combination of itertools.cycle and re.sub:

import itertools
import re

quotes = itertools.cycle (['&ldquot;', '&rdquot;'])
def sub (match):
  return quotes.next ()

text = 'The "quick" brown "fox" jumps over the "lazy" dog.'
print re.sub ('"', sub, text)

Obviously my itertools.cycle could trivially be written as: while 1: yield '..'; yield '...', but why reinvent the wheel?

Update: Tom Lynn points out that this can be done with a straightforward regex:

text = re.sub(r’”([^”]*)”‘, r’&ldquot;\1&rdquot;’, text)

Poppy Day again…

It was quite a while before I realised that using Poppies to commemorate Remembrance Sunday (and the fallen of wars in general) wasn’t universal. I don’t know if it’s practised anywhere outside the UK, in fact. But here it’s pretty much the only one of the many collections-for-good-causes which has widespread appeal, partly because it’s a tradition which long precedes pretty much every other save-the-something collection. Partly, I think, because we’re all human and who can argue with collecting money for such a cause?

As it happens I haven’t seen many poppy-sellers around where I work in Camden Town. But I knew that today — Saturday before Remembrance Sunday — the local cadets would be out in force (and in fatigues) around Ealing where I live, armed with Poppies and collecting tins. And they didn’t disappoint. I am, for several reasons, not a great fan of cadets and school OTC outfits. But, at least where I live, this is pretty much the only example of seeing groups of young people on the street doing something for the good of others. The Scout movement has reinvented itself as a training scheme, as far as I can see; and in any case, it’s been years since anyone would have been seen dead on the street in a Scout uniform.

So I bought my poppy from a young man in army outfit who looked a little lonely at the side of the main Shopping Centre square. And I hope you’ll all do the same.

London Python Dojo: that was interesting…

Thursday night saw the third London Python Dojo, which involved us completing a — very simple — noughts & crosses game, with a random computer player which seemed have a winning streak a lot of the time!

Why interesting? Because, for whatever combination of reasons, there were fewer people there: about 10 of us, compared to something around 25 the last couple of times. One obvious factor was that it was November the 5th, so many people would have been with their families at fireworks displays. It might be that the attraction had palled, but I doubt if that accounts for everyone. However it came about, we had a reduced number.

That meant two things, I think: that everyone had a go at piloting (or at least co-piloting; I don’t thing Peter actually coded at all); and that everyone was engaged to a greater extent, just because there were fewer people. (Possibly also because those who did come were slightly keener…). I had a great time, and the audience participation, which was certainly there as I made a mull of trying to get clever with an itertools.cycle, was more — how shall I put it? — manageable. It also meant that there were fewer people still at the pub, and we had a quiet corner to ourselves, which I find more pleasant than shouting at someone in an awkward corner of a noisy and crowded room. (But then, I’m not really a pub person).

Apart from small bits and pieces, most of the time around the pub table was spent debating a proposal of Jon’s that Security bugs are always logically more important than any other class of bugs, because whatever effect another bug can be caused can just as well be caused by someone breaking into your system, making that happen, and then doing whatever they were going to do anyway (sending your credit card details to the Russian mafia, etc…).

As Nicholas has already posted, we discussed various ideas around the future of this particular meetup. We definitely all agreed that it should *have* a future, and more or less coalesced around the idea of a regular, but varying, lineup which might include Dojos of different types, but would also have more conventional talks / lightning talks etc. The idea also would be to keep it in the first week of the month, thus alternating with the Pyssup which is in the third week, but varying there’s always some day *someone* can never make. (For me, it’s Wednesday). It was also agreed that “official” communications would happen on the Python-UK list as everyone can easily see that; not everyone has Twitter / Wave / the-latest-and-greatest-thing.

Personally, I think Fry-IT are very generous in not only allowing us to use their offices, but also providing beer & pizzas. It makes it much easier to talk to people before, after (and even during). If you’re in or around London in the first week of December, why not turn up? Watch the python-uk mailing list for info.

Moratorium on Python language changes?

Guido’s proposing a moratorium on changes to the Python language, the idea being to enable alternative implementations to have a stable target to aim at. This only applies to the syntax of the language, not to the stdlib, nor to the underlying implementation: the announcement hints at acceptance for a GIL-free implementation if one came along.

I’m all for it, myself. Like other people, I believe that the stdlib needs lots of care and attention in several respects. Removing one focus of changes will result in at least some of that effort shifting to the stdlib. (Altho’ it will probably result in some of the effort simply going elsewhere :) ).

Bottom-posting considered confusing?

Not a specifically Python-related post, although most of my mailing list activity is Python-related. Anyone who’s spent a more than negligible amount of time following any of the Python lists will have encountered the “We Bottom-Post Here” reaction to posters who top-post. Personally it makes sense to me, altho’ I do sometimes feel that people are too forthright about things of this sort.

That said, my experience among practically all my colleagues, friends and relations is that bottom-posting or inter-posting (ie snipping segments of an email and replying to them immediately afterwards) is downright confusing. You can blame the phenomenon on the default behaviour of certainly commonly-used email clients if you like. But I’ve had several people reply to me in puzzled tones along the lines of “Why do you put your comments under my comments like that?” or even “I think you pressed the Send key too soon…” when I’d replied at the bottom of their email rather than at the top where they expected it.

Ultimately, When in Rome… I think bottom/interposting makes more sense, but if it makes less sense to my correspondents then I view that as my problem and not theirs.