TypeError: argument of type 'int' is not iterable
时间: 2023-10-27 11:11:05 浏览: 39
This error occurs when you try to iterate over an integer value which is not iterable. Iterables are objects that can be looped over, such as lists, tuples, and dictionaries.
For example, if you try to loop over an integer value like this:
```
for i in 5:
print(i)
```
You will get the following error:
```
TypeError: argument of type 'int' is not iterable
```
To fix this error, make sure you are using an iterable object in your loop. If you want to loop over a range of numbers, you can use the built-in `range()` function:
```
for i in range(5):
print(i)
```
This will print the numbers 0 to 4.
相关问题
TypeError: argument of type 'numpy.int64' is not iterable
这个错误通常会出现在使用NumPy中的某些函数时,因为该函数需要一个可迭代的对象作为输入参数,但输入了一个整数或其他不可迭代的对象。
可能的解决方案:
1. 检查代码中使用的所有NumPy函数,并确保传递给它们的参数是可迭代的对象。
2. 如果输入参数是整数,可以将其转换为列表或数组,以便可以进行迭代。例如,可以使用`[number]`将整数转换为包含该整数的列表。
3. 如果您不确定哪个函数导致了错误,请逐步调试代码并打印变量以查找问题。
if 'S6.4.1' in row[0].value: TypeError: argument of type 'int' is not iterable
抱歉,这是我的失误。在上面的代码中,`row[0].value`是一个字符串,因此应该使用`in`来判断字符串是否包含目标子串。在修改后的代码中,我们应该使用`str(row[0].value)`将该单元格的值转换为字符串,然后再对其进行判断。
以下是修改后的代码:
```python
from openpyxl import load_workbook
# 打开Excel文件
wb = load_workbook(filename='C_Geely_Lotus DMS 20230606.xlsx')
# 选择Release Matrix-Lambda表格
ws = wb['Release Matrix-Lambda']
# 遍历每一行
for row in ws.iter_rows(min_row=2):
# 判断第一列是否包含目标字符串
if 'S6.4.1' in str(row[0].value):
# 输出对应的行数
print(row[0].row)
```
这样就可以正常运行了。