Alright, so I know the Python programming language is actually named after the Monty Python group, but after all, the language’s logo (shown here) is a pair of snakes.
One of the great things about the site is how easy it has been to build the worksheets using Python, and it’s definitely gotten me out of some jams. Like today. I built all of the recent geometry worksheets using graphics saved in PNG format, which is a loss-less file format, making it somewhat more attractive relative to the older JPEG format. PNG isn’t a terribly new file format, but some people (including my wife) have had trouble printing the new worksheets. What I really needed to do was convert the 361 PNG files on which I’d labored over into JPEGs and then regenerate the worksheets. Not much fun for a lazy guy like me.
There’s undoubtedly a bunch of freeware graphics converter programs around, but picking out an easy to use one that wasn’t loaded down with adware or spyware isn’t exactly how I wanted to spend my Saturday morning. Enter Python and the awesome Python Imaging Library.
In just a 126 bytes, I had my PNG to JPG converter together…
import os, Image
for fn in os.listdir('.'):
if fn[-4:] == '.png':
Image.open( fn ).save( fn[:-4] + '.jpg' )
If you were having trouble printing any of the new geometry worksheets, please try again.
Thank you, Python!