Browse Source

add a helper to skip some non-exist fields

Xi Ruoyao 4 years ago
parent
commit
e78bcf4e14
1 changed files with 3 additions and 1 deletions
  1. 3 1
      csv_parser.py

+ 3 - 1
csv_parser.py

@@ -18,6 +18,8 @@ def do_convert(s, fmt):
         return s
     if fmt == 'f':
         return float(s)
+    if fmt == 'n':
+        return "null"
     throw("what is this format?")
 
 def data_from_row(d):
@@ -32,7 +34,7 @@ def data_from_row(d):
             st = d['\ufeff' + name]
         else:
             st = ''
-        if st == '':
+        if st == '' and fmt != 'n':
             raise KeyError
         d1[field] = do_convert(st, fmt)
     if d1['lat'] == 0: