Archive for December, 2010

Get your Wu-name in six lines of Python

I recently had a need to generate screen-names for a bunch of test users. I remembered the wonderful Wu-name generator and it was too tempting to pass up.

import urllib
from lxml.html import fromstring
def get_wu_name(first_name, last_name):
    >>> get_wu_name("Jeff", "Elmore")
    'Ultra-Chronic Monstah'
    w = urllib.urlopen("",
                       urllib.urlencode({'fname':first_name, 'sname': last_name}))
    doc = fromstring(
    return [d for d in doc.iter('span') if d.get('class') == 'newname'][0].text

Okay, technically it’s more than six if you count the docstring and linewrap but still. Also, I felt like there should be a better way to do the last line, but this works well enough.


  • Ah that special feeling when a single plot is so elegant and concise that you can delete three other plots and about 1,000 words. 3 weeks ago
  • I can tell that my analysis just completed because my CPU fan finally ceased its high-pitched whine. That is surprisingly satisfying. 4 weeks ago
  • @mpbtownsend cool cool. I'll send something soon 1 month ago
  • @mpbtownsend either way I'm happy to share my AERA paper with you once I write it hahaha. I'd love to get your feedback! 1 month ago
  • @mpbtownsend will you be at AERA this year? I'll be presenting much of the same material 1 month ago