Skip to content

Commit 3e42f1e

Browse files
committed
更新逐行文件读取工具类支持csv
1 parent 6336c39 commit 3e42f1e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

tools/html.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__author__ = 'zhanghe'
33

44
import re
5+
import json
56

67

78
def replace_html(input_html, reg_expression=r'', replace_text=''):
@@ -82,15 +83,19 @@ def read_file(file_path):
8283
return f.read()
8384

8485

85-
def read_file_each_line(file_path):
86+
def read_file_each_line(file_path, file_type='json'):
8687
"""
8788
逐行读取文件
8889
:param file_path:
90+
:param file_type:
8991
:return:
9092
"""
9193
with open(file_path, 'r') as f:
9294
for each_line in f:
93-
yield each_line
95+
if file_type == 'json':
96+
yield json.loads(each_line)
97+
if file_type == 'csv':
98+
yield each_line
9499

95100

96101
def save_file(file_path, text, save_type='w'):

0 commit comments

Comments
 (0)