Explorar o código

Now handling degenerate case

andreagus %!s(int64=8) %!d(string=hai) anos
pai
achega
6eb07270d5
Modificáronse 1 ficheiros con 9 adicións e 3 borrados
  1. 9 3
      converter.py

+ 9 - 3
converter.py

@@ -11,7 +11,13 @@ with open(file_name_csv, 'wb') as csvfile:
     for neighbor in root.iter('DATI'):
         parent = neighbor.attrib.get("ISTANTE")
         parent = parent[:-4]
-        vm = neighbor[0].text
-        vmin = neighbor[1].text
-        vmax = neighbor[2].text
+        number = len(neighbor.getchildren())
+        if number > 1:
+            vm = neighbor[0].text
+            vmin = neighbor[1].text
+            vmax = neighbor[2].text
+        else:
+            vm = "NA"
+            vmin = "NA"
+            vmax = "NA"
         spamwriter.writerow([parent, vm, vmin, vmax])