Python goodie snippets

A couple of snippets from the Daily Python-URL digest: closures in Python, and object orientation isn’t everything.


I am slain. :(

Thanks for the bad news, Rich…

We must all now listen to crazy breakbeat music followed closely by Gambian jazz and old 78s, in remembrance.

Sitting on a stockpile of queer smut

Check his flower pot. Check his flower pot for gay porn. Classic.

Operating Systems in Python

More project ideas for next year: further to this post about writing an operating system kernel in Haskell, it looks like some crazy dudes are doing similar things using Python. Ladies and gentlemen, we present: Cleese, and the delightfully-named Unununium [python-list].

Apparently Cleese started with the idea to “make the Python intepreter a micro-kernel and boot directly to the Python prompt.”, but it doesn’t look like there’s been any movement there over a year, and hasn’t released any files.

Unununium looks interesting, and very much under development. The introduction states that components and a unified filesystem namespace (a la Plan 9) are key goals.

OK, maybe all this is too flakey and out-there for a decent project, but nonetheless, nice to know it’s happening.

Alien Loves Predator

Alien Loves Predator [ntk]: Kevin Bacon, Swipe It.

Valid use of the blink tag

Courtesy of TR, there is one valid use for the <blink> tag

March against racism, Saturday 9th October

Images (from my phone) from last Saturday’s march against racism here in Swansea:

Marching down St Helen's Road (1) (640 x 480, 29.18 kb) Marching down St Helen's Road (2) (640 x 480, 39.74 kb) Marching down St Helen's Road (3) (480 x 640, 30.96 kb) Cheerful Cheerleader (640 x 480, 28.05 kb) Gathering at Castle Square (640 x 480, 45.20 kb) Observers (640 x 480, 33.28 kb) Swansea says no (640 x 480, 42.57 kb) Rally at Castle Square (640 x 480, 41.16 kb) Swansea Unite (640 x 480, 38.61 kb) PEAC!!! (640 x 480, 25.88 kb)

As ever, Will has got much better pictures, both technically and aesthetically.

I thought the march was a little disappointing – there seemed to be many people when we were strung out along St Helen’s Road, but when we all gathered in Castle Square at the end, it didn’t seem so large. One of my colleagues, Markus Mickelbrink, went further and said the whole thing was a waste of time, because it was a load of rhetoric about “racism isn’t acceptable, Swansea is a good place for refugees, etc.” without any thought about why, then, things like this were happening – clearly some people in Swansea (and the UK in general) are virulently racist, and do blame refugees, asylum seekers, and anyone who looks/acts different for all the ills of the world – and what do we do about that? He had a point, although I disagree with him when he says doing nothing would have been better…

Generating Python module dependency graphs

Generating Python module dependency graphs in three easy steps. Yay.

10,000 factorial in lisp

And now, in lisp, courtesy of the delightfully-named Sam Vevang:

(define (fact a b) ; where a is 1 and b is 10000
  (define (iter a result)
    (if (&gt; a b)
        (iter (+ a 1) (* result a))))
  (iter a 1))

Sam tells me that when he runs this on the STK scheme interpreter, it gives the same result I got.

Man, I really need a commenting system, don’t I? :-(

Welcome to

Gimboland continues to turn into… Peter William Lount, editor of shows us how to do it in Smalltalk. Apparently Smalltalk’s been able to do this since about 1980. When I did my first degree, the boys doing straight Computing (I was doing Computing & Pure Maths, not gay Computing, by the way) met Smalltalk as their first O-O language, but alas I never had any serious exposure. The main impression I was left with was of every Smalltalk program being somehow an image of an entire virtual machine, which seemed odd and limiting but was probably neither (this was ten years ago, btw). *Shrug*

Moving on a few years, it had to happen, Daniel Berger wrote and told me how to do it in Ruby. He say:

Hi, I thought this might interest you. Here’s a “factorial” method in Ruby:

class Integer
    def factorial
        (1..self).inject { |f, n| f * n }

… and, with that in place, we can now do this:

10.factorial -&gt; 3628800
10000.factorial -&gt; really big number

Or, you could just do that as a standalone method, rather than defining it within the Integer class like so:

(1..10).inject{ |sum,n| sum * n } -&gt; 3628800

Yes, Ruby handles bignums “out of the box”. :) Regards, Dan

Fair enough, though to my mind this is at least as esoteric as the Pythonic reduce-based method mentioned previously. Again, provided you know the semantics of insert, I guess it makes perfect sense. For my money the Haskell version is still the nicest, just because it’s closest to how a mathematician would naturally go about defining factorial. Smalltalk comes close – it looks the part, but there’s still some odd syntax there, IMHO.

This is great. What started out as a glib comment which at the back of my mind I thought was probably wrong but hey, no-one ever reads Gimboland so what the heck, has turned into a nice little thread… :-)

Any other takers?

Domain Specific Languages

For my later digestion, a raw dump of a number of bookmarks on Domain Specific Languages and Haskell: one, two, three, four (which has many more links). Thank you.

More on factorial in Python

More stuff over at tiddly-pom on the whole 10,000 factorial thing. Julian does a good job of pointing at me and laughing (rightly so, rightly so), and there are a couple of imperative approaches to the problem suggested, including one using generators – yay.

Of course, something I forgot to point out about Stephen’s reduce based solution is that it’s a functional approach, and so has more in common with what’s happening in the Haskell version than these imperative versions. Anyway.

Don’t let it get your cursor!

Cute as.

Fast Easy Database Access with Python

Fast, Easy Database Access with Python. Idioms and tips for making SQL interaction that little bit less painful, that little bit more pythonic…

hOp – a micro-kernel based on the Glasgow Haskell Compiler

Wow… Potential third year project supervision material for next year: hOp, a microkernel based on the Glasgow Haskell Compiler, in which “experimenting with writing drivers in Haskell should be reasonably easy“. Funky as. [lambda]