Recently in Python Category

Times the Times Tables

My nine-year-old daughter is really slow at addition, subtraction, and multiplication—she often needs to use her fingers to do simple calculations. This is very worrisome to me because arithmetic is the foundation of so much mathematics that her inability is going to be a serious problem soon.

My wife and I learned arithmetic using verbalized tables that we had to memorize. That's out of style in American education nowadays, but it's really an effective technique. Rather than have one of us recite them over and over with her, we thought that this was a perfect application for technology.

I surveyed the available options on the App Store and none of them offered audio recitation of the times tables. My wife reminded me that the iTunes Store would probably have something, so I opened the iTunes app. They had times tables, but each number was a separate track and they were very kitschy: one set, in fact, had each number done in the style of a different rapper.

This was ridiculous! I certainly had no intention of paying $9.99 for recordings of dubious utility. Luckily, I'm a geek and this is a very simple problem:

Generate 144 strings and make a recording of a computer voice verbalizing them.

I have a Mac so Python was an obvious choice:

for i in range(2, 13):
    for j in range(1, 13):
    	print(`i` + " times " + `j` + " is " + `(i*j)` + "\r\n\r\n")

Save the file somewhere as times_tables.py and fire up the Terminal.

This is where it gets amazingly easy! There's a say command built in to Mac OS X, which uses any number of voices and outputs in many formats. I chose to make an AAC (iPhone-friendly format) version like so:

python times_table.py | say -v Alex -o times-tables.m4a --data-format=aac

That's it! I tried a bunch of the varieties and "Alex" was the most melodious, human sounding voice I could find.

[UPDATE: Here's a preview (and download) if you want to hear it.]

Dabbling with Linux

I've finally decided to take the plunge: I'm installing a Linux distro as a VM on my Mac.

I have resisted doing this for years and years and years. I've long thought that going Linux just meant that you're doomed to perennial tweaking and figuring out incompatible drivers. I don't give a rip about either of the "free as in's" when it comes to operating systems—I'm an unabashed Mac user, I pay for all of my software, and my programmatic life is completely Windows-based.

So why am I doing this? And why now?

Python.

I have been reading some really intriguing books on data analysis, social networking, and monitoring and all of the examples are in Python. I've always been tempted by Python the language and Python the community, and I've even made minor forays into that world. I know that Mac OS X is a great platform for Python but I have zero familiarity with Linux.

In the end, if I make anything significant, I'm going to want to host it on Linux so why not start now. With a virtual machine, I can duplicate my final environment without polluting my Mac or worrying about the differences between the two. I initially looked at Ubuntu but I think it's really more of a consumer-grade distro whereas I want raw server.

A colleague at work said that he uses CentOS; I figured that's as good as any and he certainly knows more than I do. So I downloaded CentOS 6.0 minimal and I'll see how it goes.

On the Side

I've started working on a personal project using Python and the Django Web framework. I'm still at the very beginning, but I really like the philosophy and idea behind Django.

The URLconf and Views stuff is extremely close to the URL rewriting HttpModule I created for Quick Blog. It's better in nearly every way, but I think I did pretty well considering it was my first pass at the idea and I did some things that ASP.NET applications normally don't do.

I'm not going to reveal the nature of the project at this time, but I will say that it will be free, help my fellow citizens inestimably, and will thwart a local municipality's efforts. I will chronicle its development once I'm well underway but I don't want to announce anything when I'm not far along at all.

Python Pitfalls


For future reference: Python Pitfalls, the gotchas of Python.


About this Archive

This page is an archive of recent entries in the Python category.

Psychology is the previous category.

Quick Quotes is the next category.

Find recent content on the main index or look in the archives to find all content.

Feedback to

Monthly Archives