File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ def csv_to_json_dict(csv_filepath):
4444 """
4545 try :
4646 with open (csv_filepath , "r" , encoding = "utf-8" ) as csvfile :
47- reader = csv .reader (csvfile )
47+ reader = csv .reader (csvfile , skipinitialspace = True )
4848
4949 # Read the header row (column names)
5050 try :
@@ -58,19 +58,19 @@ def csv_to_json_dict(csv_filepath):
5858 json .dumps ({}, indent = 2 )
5959 return
6060
61- other_column_names = [ name . strip () for name in header [ 1 :]]
61+ header_length = len ( header )
6262
6363 data_dict = {}
6464
6565 for row in reader :
66- if len (row ) != len ( header ) :
66+ if len (row ) != header_length :
6767 raise csv .Error ("Inconsistent CSV file" )
6868 exit (1 )
6969
7070 key = row [0 ]
7171 value_map = {}
7272
73- for i , col_name in enumerate (other_column_names ):
73+ for i , col_name in enumerate (header [ 1 :] ):
7474 # +1 to skip the first column
7575 value_map [col_name ] = row [i + 1 ].strip ()
7676
You can’t perform that action at this time.
0 commit comments