File tree Expand file tree Collapse file tree 4 files changed +4
-8
lines changed Expand file tree Collapse file tree 4 files changed +4
-8
lines changed Original file line number Diff line number Diff line change 3
3
4
4
file_name = input ("Provide the CSV filename without extension>> " )
5
5
6
-
7
-
8
- with open (file_name + '.csv' ) as f :
6
+ with open (file_name + '.csv' ) as f :
9
7
10
8
reader = csv .reader (f , delimiter = ',' )
11
9
12
10
titles = []
13
11
temp_data = {}
14
12
15
13
for heading in reader :
16
- print (heading )
17
14
titles = heading
18
15
break
19
16
20
17
i = 1
21
18
22
19
for row in reader :
23
- print (row )
24
20
current_row = "row{}" .format (i )
25
21
temp_data ['{}' .format (current_row )] = {}
26
22
for col in range (len (titles )):
27
23
temp_data [current_row ][titles [col ]] = row [col ]
28
- i += 1
24
+ i += 1
29
25
30
- with open (file_name + '.json' , 'w' ) as f_j :
26
+ with open (file_name + '.json' , 'w' ) as f_j :
31
27
json .dump (temp_data , f_j , indent = 4 )
32
28
33
- print ("File converted successfully :)" )
29
+ print ("File converted successfully :)\n " )
You can’t perform that action at this time.
0 commit comments