Category Archives: Software
Tuple Trivia
A couple of minor points regarding tuples. When you take a slice of a tuple, there are 3 parameters: – the start index – the end index – the step which produces: It doesn’t matter that, in the second instance, … Continue reading
globals and __main__: a Python gotcha
One of the good features is the lack of gotchas. I define gotchas as traps for the unwary programmer, where something unexpected happens. Thankfully these are rare in Python. But the following is one that is worth knowing about. Consider … Continue reading
Edge case for split / explode
During recent coding, using PHP, I found that the explode function behaves in a non-ideal way (for me) when trying to split an empty string: produces: I was expecting (needing?) an empty array. After thinking about it a bit more, … Continue reading
Reading gzip files in Python – fast!
I have been doing lots of parsing of Apache log files recently with Python. Speed is of the essence, so I was interested to know if the speed issues mentioned in http://bugs.python.org/issue7471 are still relevant. So I set out to … Continue reading
Python Standard Library
There are some gems in the Python standard library which, once found, get regular use – at least by me. Here are some of them. 1. enumerate A built-in function, which allows you to replace code like this: with the … Continue reading
Python regular expression surprise
I came across this regular expression anomaly recently in Python. The regular expression was more complex, but this example illustrates the idea. Try and predict the outcome (should work with Python 2.5 – Python 3.1) This produces: a, bc, d … Continue reading
SendKeys in Linux
SendKeys is a useful function in the Windows API which enables a program to send keystrokes. I was looking for an equivalent in Linux, first in Ubuntu at home, and then in Fedora 13 at work. For Ubuntu (Hardy Heron, … Continue reading
ctypes and addressof
Here’s a gotcha I came across in ctypes a while ago. Have a look at the code below, and see if you can work out what it will print: If you’re using Python 2.x or Python 3.x, then you might … Continue reading
Python decorators
I have been learning about decorators recently. It is interesting functionality, but also one of those areas where the issues just keep appearing, the more you look at it. There are some good articles on it here and here To … Continue reading
Ubuntu upgrade
I wanted to install an Ubuntu upgrade on a very old machine, from 8.04 LTS (Hardy Heron) to 10.04 LTS (Lucid Lynx). I like Ubuntu, so please do not take this post as a moan about it. (See here for … Continue reading