@@ -95,16 +95,16 @@ def write_headers(self):
9595 self .csv_writer .writeheader ()
9696
9797 def write_obj (self , obj ):
98- self .csv_writer .writerow (self .patch_obj (obj ))
98+ patched_obj = {
99+ key : self .patch_value (value )
100+ for key , value in obj .items ()
101+ }
102+ self .csv_writer .writerow (patched_obj )
99103
100- def patch_obj (self , obj ):
101- new_obj = {}
102- for key , value in obj .items ():
103- if value in [None , {}, []]:
104- value = ""
105-
106- new_obj [key ] = value
107- return new_obj
104+ def patch_value (self , value ):
105+ if value in (None , {}, []):
106+ return ""
107+ return value
108108
109109
110110class DumpXLS (DumpExcel ):
@@ -128,6 +128,9 @@ def write_obj(self, obj):
128128
129129 for head in self ._headers :
130130 value = obj .get (head )
131+ # patch
132+ if value in ({},):
133+ value = "{}"
131134 self .ws .write (self .row , self .cloumn , value )
132135 self .cloumn += 1
133136
@@ -138,7 +141,7 @@ def on_finish(self):
138141
139142
140143def dump_excel (fin , fout , klass , ** kwargs ):
141- if not issubclass (klass , DumpExcel ):
144+ if not isinstance ( klass , type ) or not issubclass (klass , DumpExcel ):
142145 raise ValueError ("unknow dumpexcel type" )
143146
144147 dump = klass (fin , fout , ** kwargs )
0 commit comments