source: main/waeup.kofa/trunk/tools/add_old_id_col.py

Last change on this file 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
Line 
1"""Add a new column old id with contents from col `student_id`
2"""
3
4###
5### CONFIGURATION
6###
7
8IN_FILE = 'mytry.csv'
9
10# new col name. 'old_id' is expected by fix_import_file.py
11NEW_COL = 'old_id'
12
13###
14### CONFIGURATION - END
15###
16
17
18import csv
19OUT_FILE = '%s_edited.csv' % IN_FILE.split('.')[0]
20reader = csv.DictReader(open(IN_FILE, 'rb'))
21
22for 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
31print "RESULT in ", OUT_FILE
Note: See TracBrowser for help on using the repository browser.