Use StringIO instead of appends.