We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 42ae762 commit 6336c39Copy full SHA for 6336c39
1 file changed
tools/export.py
@@ -34,9 +34,9 @@ def close(self):
34
self.bulk_fp.close()
35
36
37
-class ExportJson(object):
+class ExportFile(object):
38
"""
39
- 导出json文件工具类
+ 导出json/csv文件工具类
40
41
def __init__(self, file_name):
42
if file_name is None:
@@ -46,11 +46,14 @@ def __init__(self, file_name):
46
os.mkdir(file_path)
47
self.json_fp = open(file_name, 'a')
48
49
- def write(self, data):
+ def write(self, data, file_type='json'):
50
51
文件写入
52
53
- self.json_fp.write(json.dumps(data).decode('raw_unicode_escape')+"\n")
+ 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")
57
58
def close(self):
59
0 commit comments