Exercise: Refactoring - Extract CSV Reading Into Function (csv.reader
)¶
Requirement¶
Following Exercise: Read CSV File (csv.reader), refactor read-userdb.py
to not
directly output the user records as specified.
Rather, create a function that reads the CSV file, and returns a list of user records - dictionaries with specified keys - of the form,
{
'id': 2, # int
'firstname': 'Jörg',
'lastname': 'Faschingbauer',
'birth': '19.6.1966',
}
That list is then used as follows in the main part of the program (the part that creates the output which remains the same):
user_records = read_csv_noheader(filename)
for rec in user_records:
... create output like before, no change ...