Python version of seq for OSX

OSX is based on BSD, so it is missing some of the standard GNU utilities we’ve come to expect on a linux-y system. The most frequently used of these missing utilities is the seq utility, which is used to define a range of numbers, very useful in quick loops from the command line:

$ seq 6 12
6
7
8
9
10
11
12

You can also use the -w flag to get zero-padded output:

$ seq -w 6 12
06
07
08
09
10
11
12

The nearest BSD equivalent is something called jot which of course has more functionality but is not compatible with good old seq. I wrote a quick and dirty python script to emulate the simple behaviors of seq, specifically the base counting behavior and the -w behavior. Put it somewhere on your path (I’d suggest ~/bin/) and you should be good to go:

#!/usr/bin/env python

import sys, math

if len(sys.argv) < 3:
    print "Usage: %s [-w] min max" % sys.argv[0]
    sys.exit(1)

try:
    if len(sys.argv) == 4:
        wide = True
        min = int(sys.argv[2])
        max = int(sys.argv[3])
    else:
        wide = False
        min = int(sys.argv[1])
        max = int(sys.argv[2])
except:
    print "Error: min and max must be integers"
    sys.exit(1)

width = int(math.ceil(math.log10(max)))

for i in range(min, max + 1):
    if wide:
        print "%0*d" % (width, i)
    else:
        print "%d" % i

Update LXML on OS X

The Python scripting language is used for many extentions, add-ons and filters in the Inkscape vector graphics application. Unfortunately, Mac OS X doesn’t ship with very recent versions of some commonly used Python libraries, most notably an XML and HTML processing library called LXML. To install a more recent version, you can issue this command from the terminal:

sudo easy_install lxml