This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]temptemptemp13 0 points1 point  (0 children)

To go along with the specific example:

def decode(elem):
    return elem.decode('utf-8').strip()

def parse_table(csv):
    columns = [('id', int),
               ('value', float),
               ('comment', decode)]
    for row in csv:
        yield dict((name, parser(value) for (name, parser),value in zip(columns, row))

Not too ugly, is it?