Do you actually need to use a file here, or would a StringIO do?