Random CSV processor

Python

Public Domain

Nothing special, just a few reminders

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import csv
import sys

file = open(sys.argv[1])
reader = csv.reader(file)
rows = []
newrows = []

for row in reader:
    rows.append(row)

file.close()

for row in rows:
    name = row[0].split()
    email = row[1]
    first_name = name[0]
    last_name = name[1:]
    last_name = ' '.join(last_name)
    newrows.append([email, first_name, last_name])
   

file = sys.stdout
writer = csv.writer(file)

for row in newrows:
    writer.writerow(row)