TypeError: glob() got an unexpected keyword argument 'recursive'
时间: 2024-01-10 19:04:29 浏览: 30
这个错误是因为在使用`glob.glob()`函数时,传递了一个不支持的关键字参数`recursive`。根据Python的官方文档,`glob.glob()`函数不支持`recursive`参数。如果你想要递归地搜索文件,可以使用`os.walk()`函数来代替。下面是一个示例代码:
```python
import os
file_list = []
for root, dirs, files in os.walk(dcm_path):
for file in files:
if file.endswith(".dcm"):
file_list.append(os.path.join(root, file))
print(file_list)
```
这段代码会递归地搜索指定路径下的所有`.dcm`文件,并将它们的路径存储在`file_list`列表中。
相关问题
TypeError: glob() got an unexpected keyword argument 'dir_fd'
TypeError: glob() got an unexpected keyword argument 'dir_fd' 是一个错误信息,它表示在调用glob()函数时出现了意外的关键字参数'dir_fd'。glob()函数用于根据通配符模式匹配文件路径名。根据官方文档,glob()函数并不接受'dir_fd'参数,因此出现此错误可能是因为代码中错误地使用了此参数。
TypeError: got an unexpected keyword argument 'average'
这个错误通常是因为你使用的函数或方法不支持average参数,或者你的参数拼写错误。你可以检查一下你的代码,看看是否有拼写错误或者参数错误。如果你确定你的代码没有问题,那么可能是你使用的库版本过低,需要升级到最新版本。
以下是一个例子,演示了这个错误的产生和解决方法:
<<引用>>:
```python
import numpy as np
a = np.array([1, 2, 3, 4, 5])
print(np.average(a, axis=0, weights=[0.1, 0.2, 0.3, 0.2, 0.2], average='weighted'))
```
运行上述代码会报错:TypeError: average() got an unexpected keyword argument 'average'
<<引用>>:
解决方法是检查一下你使用的库版本是否支持average参数,如果不支持,可以升级到最新版本。如果你确定你的代码没有问题,那么可能是你使用的库版本过低,需要升级到最新版本。
```python
import numpy as np
a = np.array([1, 2, 3, 4, 5])
print(np.average(a, axis=0, weights=[0.1, 0.2, 0.3, 0.2, 0.2]))
```
输出结果为:3.1