@@ -31,10 +31,11 @@ def checkOptions(optionsUser, attr, defaultValue):
3131 if options ["error" ] == "no" :
3232 print ("Useless informations : just use try catch if you don't want error :)" )
3333 if isinstance (pathToFile , str ):
34- if isfile (pathToFile ):
34+ if not isfile (pathToFile ):
3535 if options ["error" ] == "no" :
3636 return []
37- # throw new Error("Can't access to the file")
37+ else :
38+ raise ValueError ("Can't access to the file : '{}'" .format (pathToFile ))
3839
3940 if isinstance (pathToFile , str ):
4041 csvFile = open (pathToFile )
@@ -114,9 +115,10 @@ def parseLine(line):
114115 if index == - 1 :
115116 currentValue = schemaValue
116117 else :
117- currentValue = allValues [index ] or ""
118- if options ["parse" ] == True :
119- if schemaValue == "int" :
118+ if index < len (allValues ):
119+ currentValue = allValues [index ]
120+ if options ["parse" ] == True and currentValue != None :
121+ if schemaValue == "int" and currentValue != '' :
120122 currentValue = int (currentValue )
121123 elif schemaValue == "float" :
122124 currentValue = float (currentValue )
@@ -144,15 +146,16 @@ def parseLine(line):
144146 if isinstance (goodPlace , dict ):
145147 goodPlace [nextPath ] = ""
146148 else :
147- if nextPath not in goodPlace :
149+ if ( isinstance ( goodPlace , list ) and nextPathInt not in goodPlace ) or nextPath not in goodPlace :
148150 if isinstance (goodPlace , list ):
149151 if len (goodPlace ) < (nextPathInt + 1 ):
150152 # len() returns 0 and the first index of the list is 0 !
151153 goodPlace .insert (nextPathInt , {})
152154 else :
153155 goodPlace [nextPath ] = {}
154156 if isinstance (goodPlace , list ):
155- goodPlace = goodPlace [nextPathInt ]
157+ if nextPathInt < len (goodPlace ):
158+ goodPlace = goodPlace [nextPathInt ]
156159 else :
157160 goodPlace = goodPlace [nextPath ]
158161 if isinstance (goodPlace , list ):
@@ -202,8 +205,10 @@ def reader():
202205 parsedLine = {}
203206 if isinstance (pathToFile , list ):
204207 oneLine = oneLine .split (options ["separator" ])
208+ elif isinstance (pathToFile , str ) and isinstance (oneLine , list ) and len (oneLine ) == 0 :
209+ oneLine = ['' ] #create a fake void line
205210 if options ["avoidVoidLine" ] == True :
206- if oneLine == "" and oneLine == "\n " or oneLine == "\r \n " :
211+ if ( isinstance ( oneLine , list ) and len ( oneLine ) == 0 ) or ( isinstance ( oneLine , list ) and len ( oneLine ) >= 1 and oneLine [ 0 ] == "" ) or oneLine == "" or oneLine == "\n " or oneLine == "\r \n " :
207212 continue
208213 parsedLine = parseLine (oneLine )
209214 if callable (options ["lineCallBack" ]):
0 commit comments