qrpa 1.0.34__py3-none-any.whl → 1.1.50__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
qrpa/fun_base.py CHANGED
@@ -1,337 +1,339 @@
1
- import inspect
2
- import os
3
- import traceback
4
- import socket
5
- import hashlib
6
- import shutil
7
-
8
- from datetime import datetime
9
-
10
- from .wxwork import WxWorkBot
11
-
12
- from .RateLimitedSender import RateLimitedSender
13
-
14
- from typing import TypedDict
15
-
16
- # 定义一个 TypedDict 来提供配置结构的类型提示
17
-
18
- class ZiNiao(TypedDict):
19
- company: str
20
- username: str
21
- password: str
22
-
23
- class Config(TypedDict):
24
- wxwork_bot_exception: str
25
- ziniao: ZiNiao
26
- auto_dir: str
27
-
28
- def log(*args, **kwargs):
29
- """封装 print 函数,使其行为与原 print 一致,并写入日志文件"""
30
- stack = inspect.stack()
31
- fi = stack[1] if len(stack) > 1 else None
32
- log_message = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}][{os.path.basename(fi.filename) if fi else 'unknown'}:{fi.lineno if fi else 0}:{fi.function if fi else 'unknown'}] " + " ".join(map(str, args))
33
-
34
- print(log_message, **kwargs)
35
-
36
- def hostname():
37
- return socket.gethostname()
38
-
39
- # ================= WxWorkBot 限频异常发送 =================
40
- def send_exception(msg=None):
41
- """
42
- 发送异常到 WxWorkBot,限制发送频率,支持异步批量
43
- """
44
- # 首次调用时初始化限频发送器
45
- if not hasattr(send_exception, "_wx_sender"):
46
- def wxwork_bot_send(message):
47
- bot_id = os.getenv('wxwork_bot_exception', 'ee5a048a-1b9e-41e4-9382-aa0ee447898e')
48
- WxWorkBot(bot_id).send_text(message)
49
-
50
- send_exception._wx_sender = RateLimitedSender(
51
- sender_func=wxwork_bot_send,
52
- interval=30, # 10 秒发一次
53
- )
54
-
55
- # 构造异常消息
56
- error_msg = f'【{hostname()}】{datetime.now():%Y-%m-%d %H:%M:%S}\n{msg}\n'
57
- error_msg += f'{traceback.format_exc()}'
58
- print(error_msg)
59
-
60
- # 异步发送
61
- send_exception._wx_sender.send(error_msg)
62
- return error_msg
63
-
64
- def get_safe_value(data, key, default=0):
65
- value = data.get(key)
66
- return default if value is None else value
67
-
68
- def md5_string(s):
69
- # 需要先将字符串编码为 bytes
70
- return hashlib.md5(s.encode('utf-8')).hexdigest()
71
-
72
- # 将windows文件名不支持的字符替换成下划线
73
- def sanitize_filename(filename):
74
- # Windows 文件名非法字符
75
- illegal_chars = r'\/:*?"<>|'
76
- for char in illegal_chars:
77
- filename = filename.replace(char, '_')
78
-
79
- # 去除首尾空格和点
80
- filename = filename.strip(' .')
81
-
82
- # 替换连续多个下划线为单个
83
- filename = '_'.join(filter(None, filename.split('_')))
84
-
85
- return filename
86
-
87
- def add_https(url):
88
- if url and url.startswith('//'):
89
- return 'https:' + url
90
- return url
91
-
92
- def create_file_path(file_path):
93
- dir_name = os.path.dirname(file_path)
94
- if dir_name and not os.path.exists(dir_name):
95
- os.makedirs(dir_name, exist_ok=True) # 递归创建目录
96
- return file_path
97
-
98
- def copy_file(source, destination):
99
- try:
100
- shutil.copy2(source, destination)
101
- print(f"文件已复制到 {destination}")
102
- except FileNotFoundError:
103
- print(f"错误:源文件 '{source}' 不存在")
104
- except PermissionError:
105
- print(f"错误:没有权限复制到 '{destination}'")
106
- except Exception as e:
107
- print(f"错误:发生未知错误 - {e}")
108
-
109
- def get_file_size(file_path, human_readable=False):
110
- """
111
- 获取文件大小
112
-
113
- :param file_path: 文件路径
114
- :param human_readable: 是否返回可读格式(KB, MB, GB)
115
- :return: 文件大小(字节数或可读格式)
116
- """
117
- if not os.path.isfile(file_path):
118
- raise FileNotFoundError(f"文件不存在: {file_path}")
119
-
120
- size_bytes = os.path.getsize(file_path)
121
-
122
- if not human_readable:
123
- return size_bytes
124
-
125
- # 转换为可读单位
126
- units = ["B", "KB", "MB", "GB", "TB"]
127
- size = float(size_bytes)
128
- for unit in units:
129
- if size < 1024:
130
- return f"{size:.2f} {unit}"
131
- size /= 1024
132
-
133
- def calculate_star_symbols(rating):
134
- """
135
- 计算星级对应的符号组合(独立评分逻辑函数)
136
- 参数:
137
- rating (int): 标准化评分(0-5)
138
- 返回:
139
- str: 星级符号字符串(如★★★⭐☆)
140
- """
141
- full_stars = int(rating)
142
- empty_stars = 5 - full_stars
143
- star_string = '★' * full_stars
144
- star_string += '☆' * empty_stars
145
- return star_string
146
-
147
- def remove_columns(matrix, indices):
148
- """
149
- 过滤二维列表,移除指定索引的列
150
-
151
- 参数:
152
- matrix: 二维列表
153
- indices: 需要移除的列索引列表
154
-
155
- 返回:
156
- 过滤后的二维列表
157
- """
158
- # 创建要保留的索引集合(排除需要移除的索引)
159
- indices_to_keep = set(range(len(matrix[0]))) - set(indices)
160
-
161
- # 遍历每行,只保留不在indices中的列
162
- return [[row[i] for i in indices_to_keep] for row in matrix]
163
-
164
-
165
- def filter_columns(matrix, indices):
166
- """
167
- 过滤二维列表,只保留指定索引的列
168
-
169
- 参数:
170
- matrix: 二维列表
171
- indices: 需要保留的列索引列表
172
-
173
- 返回:
174
- 过滤后的二维列表
175
- """
176
- # 转置矩阵,获取每一列
177
- columns = list(zip(*matrix))
178
-
179
- # 只保留指定索引的列
180
- filtered_columns = [columns[i] for i in indices]
181
-
182
- # 将过滤后的列转回二维列表
183
- return [list(row) for row in zip(*filtered_columns)]
184
-
185
-
186
- # # 示例使用
187
- # matrix = [
188
- # [1, 2, 3, 4],
189
- # [5, 6, 7, 8],
190
- # [9, 10, 11, 12]
191
- # ]
192
- #
193
- # # 只保留索引为 0 和 2 的列
194
- # filtered = filter_columns(matrix, [0, 2])
195
- # print(filtered) # 输出: [[1, 3], [5, 7], [9, 11]]
196
-
197
- def add_column_to_2d_list(data, new_col, index=None):
198
- """
199
- 给二维列表增加一列数据
200
-
201
- :param data: 原始二维列表,例如 [[1, 2], [3, 4]]
202
- :param new_col: 要添加的新列数据,例如 [10, 20]
203
- :param index: 插入位置,默认为最后一列之后;支持负数索引
204
- :return: 增加新列后的二维列表
205
- """
206
- if not data:
207
- raise ValueError("原始数据为空")
208
- if len(data) != len(new_col):
209
- raise ValueError("新列长度必须与原始数据的行数相等")
210
-
211
- new_data = []
212
- for i, row in enumerate(data):
213
- row = list(row) # 防止修改原始数据
214
- insert_at = index if index is not None else len(row)
215
- row.insert(insert_at, new_col[i])
216
- new_data.append(row)
217
- return new_data
218
-
219
-
220
- def add_prefixed_column(data, header, value):
221
- """
222
- 给二维列表增加第一列,第一行为 header,后面为 value
223
-
224
- :param data: 原始二维列表
225
- :param header: 新列的标题
226
- :param value: 新列内容(相同值)
227
- :return: 增加新列后的二维列表
228
- """
229
- if not data:
230
- raise ValueError("原始数据不能为空")
231
-
232
- new_col = [header] + [value] * (len(data) - 1)
233
- return [[new_col[i]] + row for i, row in enumerate(data)]
234
-
235
-
236
- def add_suffixed_column(data, header, value):
237
- """
238
- 给二维列表增加第一列,第一行为 header,后面为 value。
239
-
240
- :param data: 原始二维列表
241
- :param header: 新列的标题
242
- :param value: 新列内容(相同值)
243
- :return: 增加新列后的二维列表
244
- """
245
- if not data:
246
- raise ValueError("原始数据不能为空")
247
-
248
- new_col = [header] + [value] * (len(data) - 1)
249
- return [row + [new_col[i]] for i, row in enumerate(data)]
250
-
251
-
252
- def merge_2d_lists_keep_first_header(data1, data2):
253
- """
254
- 合并两个二维列表,只保留第一个列表的标题(即第一行)。
255
-
256
- :param data1: 第一个二维列表(包含标题)
257
- :param data2: 第二个二维列表(包含标题)
258
- :return: 合并后的二维列表
259
- """
260
- if not data1 or not isinstance(data1, list):
261
- raise ValueError("data1 不能为空并且必须是二维列表")
262
- if not data2 or not isinstance(data2, list):
263
- raise ValueError("data2 不能为空并且必须是二维列表")
264
-
265
- header = data1[0]
266
- rows1 = data1[1:]
267
- rows2 = data2[1:]
268
-
269
- return [header] + rows1 + rows2
270
-
271
-
272
- def insert_total_row(data, row_index=1, label="合计"):
273
- """
274
- 在指定行插入一行,第一列为 label,其余为空字符串。
275
-
276
- :param data: 原始二维列表
277
- :param row_index: 插入位置,默认插在第二行(索引1)
278
- :param label: 第一列的标签内容,默认为 "合计"
279
- :return: 新的二维列表
280
- """
281
- if not data or not isinstance(data, list):
282
- raise ValueError("data 不能为空并且必须是二维列表")
283
-
284
- num_cols = len(data[0])
285
- new_row = [label] + [""] * (num_cols - 1)
286
-
287
- return data[:row_index] + [new_row] + data[row_index:]
288
-
289
-
290
- def insert_empty_column_after(data, col_index, new_header="单价成本"):
291
- """
292
- 在二维列表中指定列的后面插入一个新列,标题为 new_header,其余内容为空字符串。
293
-
294
- :param data: 原始二维列表
295
- :param col_index: 要插入的位置(在该列后面插入)
296
- :param new_header: 新列的标题
297
- :return: 新的二维列表
298
- """
299
- if not data or not isinstance(data, list):
300
- raise ValueError("data 不能为空且必须是二维列表")
301
-
302
- new_data = []
303
- for i, row in enumerate(data):
304
- row = list(row) # 复制避免修改原数据
305
- insert_value = new_header if i == 0 else ""
306
- row.insert(col_index + 1, insert_value)
307
- new_data.append(row)
308
-
309
- return new_data
310
-
311
-
312
- def insert_empty_column_after_column_name(data, target_col_name, new_header="单价成本"):
313
- """
314
- 在指定列名对应的列后面插入一个新列,标题为 new_header,其余行为空字符串。
315
-
316
- :param data: 原始二维列表
317
- :param target_col_name: 要在哪一列之后插入(通过列标题匹配)
318
- :param new_header: 插入的新列标题
319
- :return: 新的二维列表
320
- """
321
- if not data or not isinstance(data, list):
322
- raise ValueError("data 不能为空且必须是二维列表")
323
-
324
- header = data[0]
325
- if target_col_name not in header:
326
- raise ValueError(f"找不到列名:{target_col_name}")
327
-
328
- col_index = header.index(target_col_name)
329
-
330
- new_data = []
331
- for i, row in enumerate(data):
332
- row = list(row) # 防止修改原始数据
333
- insert_value = new_header if i == 0 else ""
334
- row.insert(col_index + 1, insert_value)
335
- new_data.append(row)
336
-
337
- return new_data
1
+ import inspect
2
+ import os
3
+ import traceback
4
+ import socket
5
+ import hashlib
6
+ import shutil
7
+
8
+ from datetime import datetime
9
+
10
+ from .wxwork import WxWorkBot
11
+
12
+ from .RateLimitedSender import RateLimitedSender
13
+
14
+ from typing import TypedDict
15
+
16
+ # 自定义错误类型,继承自 Exception
17
+ class NetWorkIdleTimeout(Exception):
18
+ """这是一个自定义错误类型"""
19
+ pass
20
+
21
+ # 定义一个 TypedDict 来提供配置结构的类型提示
22
+
23
+ class ZiNiao(TypedDict):
24
+ company: str
25
+ username: str
26
+ password: str
27
+
28
+ class Config(TypedDict):
29
+ wxwork_bot_exception: str
30
+ ziniao: ZiNiao
31
+ auto_dir: str
32
+
33
+ def log(*args, **kwargs):
34
+ """封装 print 函数,使其行为与原 print 一致,并写入日志文件"""
35
+ stack = inspect.stack()
36
+ fi = stack[1] if len(stack) > 1 else None
37
+ log_message = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}][{os.path.basename(fi.filename) if fi else 'unknown'}:{fi.lineno if fi else 0}:{fi.function if fi else 'unknown'}] " + " ".join(map(str, args))
38
+
39
+ print(log_message, **kwargs)
40
+
41
+ def hostname():
42
+ return socket.gethostname()
43
+
44
+ # ================= WxWorkBot 限频异常发送 =================
45
+ def send_exception(msg=None):
46
+ """
47
+ 发送异常到 WxWorkBot,限制发送频率,支持异步批量
48
+ """
49
+ # 首次调用时初始化限频发送器
50
+ if not hasattr(send_exception, "_wx_sender"):
51
+ def wxwork_bot_send(message):
52
+ bot_id = os.getenv('wxwork_bot_exception', 'ee5a048a-1b9e-41e4-9382-aa0ee447898e')
53
+ WxWorkBot(bot_id).send_text(message)
54
+
55
+ send_exception._wx_sender = RateLimitedSender(
56
+ sender_func=wxwork_bot_send,
57
+ interval=30, # 10 秒发一次
58
+ )
59
+
60
+ # 构造异常消息
61
+ error_msg = f'【{hostname()}】{datetime.now():%Y-%m-%d %H:%M:%S}\n{msg}\n'
62
+ error_msg += f'{traceback.format_exc()}'
63
+ print(error_msg)
64
+
65
+ # 异步发送
66
+ send_exception._wx_sender.send(error_msg)
67
+ return error_msg
68
+
69
+ def get_safe_value(data, key, default=0):
70
+ value = data.get(key)
71
+ return default if value is None else value
72
+
73
+ def md5_string(s):
74
+ # 需要先将字符串编码为 bytes
75
+ return hashlib.md5(s.encode('utf-8')).hexdigest()
76
+
77
+ # 将windows文件名不支持的字符替换成下划线
78
+ def sanitize_filename(filename):
79
+ # Windows 文件名非法字符
80
+ illegal_chars = r'\/:*?"<>|'
81
+ for char in illegal_chars:
82
+ filename = filename.replace(char, '_')
83
+
84
+ # 去除首尾空格和点
85
+ filename = filename.strip(' .')
86
+
87
+ # 替换连续多个下划线为单个
88
+ filename = '_'.join(filter(None, filename.split('_')))
89
+
90
+ return filename
91
+
92
+ def add_https(url):
93
+ if url and url.startswith('//'):
94
+ return 'https:' + url
95
+ return url
96
+
97
+ def create_file_path(file_path):
98
+ dir_name = os.path.dirname(file_path)
99
+ if dir_name and not os.path.exists(dir_name):
100
+ os.makedirs(dir_name, exist_ok=True) # 递归创建目录
101
+ return file_path
102
+
103
+ def copy_file(source, destination):
104
+ try:
105
+ shutil.copy2(source, destination)
106
+ print(f"文件已复制到 {destination}")
107
+ except FileNotFoundError:
108
+ print(f"错误:源文件 '{source}' 不存在")
109
+ except PermissionError:
110
+ print(f"错误:没有权限复制到 '{destination}'")
111
+ except Exception as e:
112
+ print(f"错误:发生未知错误 - {e}")
113
+
114
+ def get_file_size(file_path, human_readable=False):
115
+ """
116
+ 获取文件大小
117
+
118
+ :param file_path: 文件路径
119
+ :param human_readable: 是否返回可读格式(KB, MB, GB)
120
+ :return: 文件大小(字节数或可读格式)
121
+ """
122
+ if not os.path.isfile(file_path):
123
+ raise FileNotFoundError(f"文件不存在: {file_path}")
124
+
125
+ size_bytes = os.path.getsize(file_path)
126
+
127
+ if not human_readable:
128
+ return size_bytes
129
+
130
+ # 转换为可读单位
131
+ units = ["B", "KB", "MB", "GB", "TB"]
132
+ size = float(size_bytes)
133
+ for unit in units:
134
+ if size < 1024:
135
+ return f"{size:.2f} {unit}"
136
+ size /= 1024
137
+
138
+ def calculate_star_symbols(rating):
139
+ """
140
+ 计算星级对应的符号组合(独立评分逻辑函数)
141
+ 参数:
142
+ rating (int): 标准化评分(0-5
143
+ 返回:
144
+ str: 星级符号字符串(如★★★⭐☆)
145
+ """
146
+ full_stars = int(rating)
147
+ empty_stars = 5 - full_stars
148
+ star_string = '★' * full_stars
149
+ star_string += '☆' * empty_stars
150
+ return star_string
151
+
152
+ def remove_columns(matrix, indices):
153
+ """
154
+ 过滤二维列表,移除指定索引的列
155
+
156
+ 参数:
157
+ matrix: 二维列表
158
+ indices: 需要移除的列索引列表
159
+
160
+ 返回:
161
+ 过滤后的二维列表
162
+ """
163
+ # 创建要保留的索引集合(排除需要移除的索引)
164
+ indices_to_keep = set(range(len(matrix[0]))) - set(indices)
165
+
166
+ # 遍历每行,只保留不在indices中的列
167
+ return [[row[i] for i in indices_to_keep] for row in matrix]
168
+
169
+ def filter_columns(matrix, indices):
170
+ """
171
+ 过滤二维列表,只保留指定索引的列
172
+
173
+ 参数:
174
+ matrix: 二维列表
175
+ indices: 需要保留的列索引列表
176
+
177
+ 返回:
178
+ 过滤后的二维列表
179
+ """
180
+ # 转置矩阵,获取每一列
181
+ columns = list(zip(*matrix))
182
+
183
+ # 只保留指定索引的列
184
+ filtered_columns = [columns[i] for i in indices]
185
+
186
+ # 将过滤后的列转回二维列表
187
+ return [list(row) for row in zip(*filtered_columns)]
188
+
189
+ # # 示例使用
190
+ # matrix = [
191
+ # [1, 2, 3, 4],
192
+ # [5, 6, 7, 8],
193
+ # [9, 10, 11, 12]
194
+ # ]
195
+ #
196
+ # # 只保留索引为 0 和 2 的列
197
+ # filtered = filter_columns(matrix, [0, 2])
198
+ # print(filtered) # 输出: [[1, 3], [5, 7], [9, 11]]
199
+
200
+ def add_column_to_2d_list(data, new_col, index=None):
201
+ """
202
+ 给二维列表增加一列数据
203
+
204
+ :param data: 原始二维列表,例如 [[1, 2], [3, 4]]
205
+ :param new_col: 要添加的新列数据,例如 [10, 20]
206
+ :param index: 插入位置,默认为最后一列之后;支持负数索引
207
+ :return: 增加新列后的二维列表
208
+ """
209
+ if not data:
210
+ raise ValueError("原始数据为空")
211
+ if len(data) != len(new_col):
212
+ raise ValueError("新列长度必须与原始数据的行数相等")
213
+
214
+ new_data = []
215
+ for i, row in enumerate(data):
216
+ row = list(row) # 防止修改原始数据
217
+ insert_at = index if index is not None else len(row)
218
+ row.insert(insert_at, new_col[i])
219
+ new_data.append(row)
220
+ return new_data
221
+
222
+ def add_prefixed_column(data, header, value):
223
+ """
224
+ 给二维列表增加第一列,第一行为 header,后面为 value。
225
+
226
+ :param data: 原始二维列表
227
+ :param header: 新列的标题
228
+ :param value: 新列内容(相同值)
229
+ :return: 增加新列后的二维列表
230
+ """
231
+ if not data:
232
+ raise ValueError("原始数据不能为空")
233
+
234
+ new_col = [header] + [value] * (len(data) - 1)
235
+ return [[new_col[i]] + row for i, row in enumerate(data)]
236
+
237
+ def add_suffixed_column(data, header, value):
238
+ """
239
+ 给二维列表增加第一列,第一行为 header,后面为 value。
240
+
241
+ :param data: 原始二维列表
242
+ :param header: 新列的标题
243
+ :param value: 新列内容(相同值)
244
+ :return: 增加新列后的二维列表
245
+ """
246
+ if not data:
247
+ raise ValueError("原始数据不能为空")
248
+
249
+ new_col = [header] + [value] * (len(data) - 1)
250
+ return [row + [new_col[i]] for i, row in enumerate(data)]
251
+
252
+ def merge_2d_lists_keep_first_header(data1, data2):
253
+ """
254
+ 合并两个二维列表,只保留第一个列表的标题(即第一行)。
255
+
256
+ :param data1: 第一个二维列表(包含标题)
257
+ :param data2: 第二个二维列表(包含标题)
258
+ :return: 合并后的二维列表
259
+ """
260
+ if not data1 or not isinstance(data1, list):
261
+ raise ValueError("data1 不能为空并且必须是二维列表")
262
+ if not data2 or not isinstance(data2, list):
263
+ raise ValueError("data2 不能为空并且必须是二维列表")
264
+
265
+ header = data1[0]
266
+ rows1 = data1[1:]
267
+ rows2 = data2[1:]
268
+
269
+ return [header] + rows1 + rows2
270
+
271
+ def insert_total_row(data, row_index=1, label="合计"):
272
+ """
273
+ 在指定行插入一行,第一列为 label,其余为空字符串。
274
+
275
+ :param data: 原始二维列表
276
+ :param row_index: 插入位置,默认插在第二行(索引1)
277
+ :param label: 第一列的标签内容,默认为 "合计"
278
+ :return: 新的二维列表
279
+ """
280
+ if not data or not isinstance(data, list):
281
+ raise ValueError("data 不能为空并且必须是二维列表")
282
+
283
+ num_cols = len(data[0])
284
+ new_row = [label] + [""] * (num_cols - 1)
285
+
286
+ return data[:row_index] + [new_row] + data[row_index:]
287
+
288
+ def insert_empty_column_after(data, col_index, new_header="单价成本"):
289
+ """
290
+ 在二维列表中指定列的后面插入一个新列,标题为 new_header,其余内容为空字符串。
291
+
292
+ :param data: 原始二维列表
293
+ :param col_index: 要插入的位置(在该列后面插入)
294
+ :param new_header: 新列的标题
295
+ :return: 新的二维列表
296
+ """
297
+ if not data or not isinstance(data, list):
298
+ raise ValueError("data 不能为空且必须是二维列表")
299
+
300
+ new_data = []
301
+ for i, row in enumerate(data):
302
+ row = list(row) # 复制避免修改原数据
303
+ insert_value = new_header if i == 0 else ""
304
+ row.insert(col_index + 1, insert_value)
305
+ new_data.append(row)
306
+
307
+ return new_data
308
+
309
+ def insert_empty_column_after_column_name(data, target_col_name, new_header="单价成本"):
310
+ """
311
+ 在指定列名对应的列后面插入一个新列,标题为 new_header,其余行为空字符串。
312
+
313
+ :param data: 原始二维列表
314
+ :param target_col_name: 要在哪一列之后插入(通过列标题匹配)
315
+ :param new_header: 插入的新列标题
316
+ :return: 新的二维列表
317
+ """
318
+ if not data or not isinstance(data, list):
319
+ raise ValueError("data 不能为空且必须是二维列表")
320
+
321
+ header = data[0]
322
+ if target_col_name not in header:
323
+ raise ValueError(f"找不到列名:{target_col_name}")
324
+
325
+ col_index = header.index(target_col_name)
326
+
327
+ new_data = []
328
+ for i, row in enumerate(data):
329
+ row = list(row) # 防止修改原始数据
330
+ insert_value = new_header if i == 0 else ""
331
+ row.insert(col_index + 1, insert_value)
332
+ new_data.append(row)
333
+
334
+ return new_data
335
+
336
+ # 去除一维列表指定项目和重复项目
337
+ def clean_list(lst, items_to_remove):
338
+ # 使用集合去重,然后去除指定项
339
+ return [x for x in list(dict.fromkeys(lst)) if x not in items_to_remove]