Stripping whitespace

ryan k ryan at
Wed Jan 23 20:17:55 CET 2008

I am taking a database class so I'm not asking for specific answers.
Well I have this text tile:

And this code:

# Table and row classes used for queries

class Row(object):
    def __init__(self, column_list, row_vals):
        print len(column_list)
        print len(row_vals)
        for column, value in column_list, row_vals:
            if column and value:
                setattr(self, column.lower(), value)

class Table(object):
    def __init__(self, table_name, table_fd): = table_name
        self.table_fd = table_fd
        self.rows = []

    def _load_table(self):
        counter = 0
        for line in self.table_fd:
            # Skip the second line
            if not '-----' in line:
                if counter == 0:
                    # This line contains the columns, parse it
                    column_list = line.split()
                    # This is a row, parse it
                    row_vals = line.split()
                    # Create a new Row object and add it to the
                    # row list
                    self.rows.append(Row(column_list, row_vals))
            counter += 1

Because the addresses contain spaces, this won't work because there
are too many values being unpacked in row's __init__'s for loop. Any
suggestions for a better way to parse this file? I don't want to cheat
but just some general ideas would be nice. Thanks!

More information about the Python-list mailing list