-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.py
50 lines (39 loc) · 1.27 KB
/
dump.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import csv
import pprint as pp
res = []
# with open('data.csv', 'r', encoding='utf-8') as file:
# mfile = csv.DictReader(file)
# for obj in mfile:
# temp = {
# 'ticket_id': obj['Ticket number'],
# 'first_name': obj['First Name'],
# 'last_name': obj['Last Name']
# }
# res.append(temp)
def parseCsv(filename):
res = []
with open(filename, 'r', encoding='utf-8') as file:
mfile = csv.DictReader(file)
for obj in mfile:
temp = {
'ticket_id': obj['Ticket number'],
'first_name': obj['First Name'],
'last_name': obj['Last Name']
}
res.append(temp)
with open('result.csv', 'w', encoding='utf-8') as file:
fieldnames = ['ticket_id', 'first_name', 'last_name']
wfile = csv.DictWriter(file, fieldnames=fieldnames, dialect='unix')
wfile.writeheader()
for row in res:
wfile.writerow(row)
return res
def readCsv(filename):
res = []
with open(filename, 'r', encoding='utf-8') as file:
mfile = csv.DictReader(file)
for obj in mfile:
res.append(obj)
return res
# pp.pprint(parseCsv('data.csv'))
# print(r)