Last change
on this file since 14292 was
9362,
checked in by uli, 12 years ago
|
Update tools to allow new ids in imports. Support for new import col 'old_id'.
|
File size:
673 bytes
|
Rev | Line | |
---|
[9362] | 1 | """Add a new column old id with contents from col `student_id` |
---|
| 2 | """ |
---|
| 3 | |
---|
| 4 | ### |
---|
| 5 | ### CONFIGURATION |
---|
| 6 | ### |
---|
| 7 | |
---|
| 8 | IN_FILE = 'mytry.csv' |
---|
| 9 | |
---|
| 10 | # new col name. 'old_id' is expected by fix_import_file.py |
---|
| 11 | NEW_COL = 'old_id' |
---|
| 12 | |
---|
| 13 | ### |
---|
| 14 | ### CONFIGURATION - END |
---|
| 15 | ### |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | import csv |
---|
| 19 | OUT_FILE = '%s_edited.csv' % IN_FILE.split('.')[0] |
---|
| 20 | reader = csv.DictReader(open(IN_FILE, 'rb')) |
---|
| 21 | |
---|
| 22 | for num, row in enumerate(reader): |
---|
| 23 | if num == 0: |
---|
| 24 | writer = csv.DictWriter( |
---|
| 25 | open(OUT_FILE, 'wb'), reader.fieldnames + [NEW_COL,]) |
---|
| 26 | header = dict([(x, x) for x in writer.fieldnames]) |
---|
| 27 | writer.writerow(header) |
---|
| 28 | row[NEW_COL] = row['student_id'] |
---|
| 29 | writer.writerow(row) |
---|
| 30 | |
---|
| 31 | print "RESULT in ", OUT_FILE |
---|
Note: See
TracBrowser for help on using the repository browser.