Skip to content

Commit 6336c39

Browse files
committed
更新文件导出类支持csv
1 parent 42ae762 commit 6336c39

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

tools/export.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def close(self):
3434
self.bulk_fp.close()
3535

3636

37-
class ExportJson(object):
37+
class ExportFile(object):
3838
"""
39-
导出json文件工具类
39+
导出json/csv文件工具类
4040
"""
4141
def __init__(self, file_name):
4242
if file_name is None:
@@ -46,11 +46,14 @@ def __init__(self, file_name):
4646
os.mkdir(file_path)
4747
self.json_fp = open(file_name, 'a')
4848

49-
def write(self, data):
49+
def write(self, data, file_type='json'):
5050
"""
5151
文件写入
5252
"""
53-
self.json_fp.write(json.dumps(data).decode('raw_unicode_escape')+"\n")
53+
if file_type == 'json':
54+
self.json_fp.write(json.dumps(data).decode('raw_unicode_escape')+"\n")
55+
if file_type == 'csv':
56+
self.json_fp.write(','.join(data)+"\n")
5457

5558
def close(self):
5659
"""

0 commit comments

Comments
 (0)