Traceback (most recent call last): File "D:\Users\Lenovo\PycharmProjects\pythonProject\1123.py", line 189, in <module> readsheetdata() File "D:\Users\Lenovo\PycharmProjects\pythonProject\1123.py", line 176, in readsheetdata min_value = min(sublist) ^^^^^^^^^^^^ ValueError: min() arg is an empty sequence
时间: 2023-07-21 16:09:52 浏览: 119
这个错误是由于你尝试对空列表调用`min()`函数导致的。当某个分列为空时,无法找到最小值。
要解决这个问题,你可以在获取分列的最小值之前,先检查分列是否为空。可以使用`if`语句来进行判断。修改后的代码如下:
```python
all_row_lists = ['6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '18', '19', '20', '21', '22', '23', '24',
'25', '26', '27', '28', '29']
split_lists = []
current_list = []
for i in range(len(all_row_lists)):
num = int(all_row_lists[i])
if i == 0:
current_list.append(num)
else:
prev_num = int(all_row_lists[i - 1])
if num - prev_num == 1:
current_list.append(num)
else:
split_lists.append(current_list)
current_list = [num]
split_lists.append(current_list)
for sublist in split_lists:
if sublist: # 检查分列是否为空
min_value = min(sublist)
max_value = max(sublist)
print(f"Min: {min_value}, Max: {max_value}")
```
这样,如果某个分列为空,就会跳过对其进行最小值和最大值的计算,避免了`ValueError`错误。
阅读全文