Python tqdm:“模块”对象不可调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39323182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tqdm: 'module' object is not callable
提问by Zhao
I import tqdm as this:
我将 tqdm 导入为:
import tqdm
I am using tqdm to show progress in my python3 code, but I have the following error:
我正在使用 tqdm 在我的 python3 代码中显示进度,但出现以下错误:
Traceback (most recent call last):
File "process.py", line 15, in <module>
for dir in tqdm(os.listdir(path), desc = 'dirs'):
TypeError: 'module' object is not callable
Here is the code:
这是代码:
path = '../dialogs'
dirs = os.listdir(path)
for dir in tqdm(dirs, desc = 'dirs'):
print(dir)
回答by idjaw
The error is telling you are trying to call the module. You can't do this.
该错误告诉您正在尝试调用该模块。你不能这样做。
To call you just have to do
打电话给你只需要做
tqdm.tqdm(dirs, desc='dirs')
to solve your problem. Or simply change your import to
解决您的问题。或者干脆将您的导入更改为
from tqdm import tqdm
But, the important thing here is to review the documentation for what you are using and ensure you are using it properly.
但是,这里重要的是查看文档以了解您正在使用的内容并确保您正确使用它。
回答by Jake
tqdm is a module (like matplotlib or pandas) that contains functions. One of these functions is called tqdm. Therefore, you have to call tqdm.tqdm to call the function within the module instead of the module itself.
tqdm 是一个包含函数的模块(如 matplotlib 或 pandas)。这些功能之一称为 tqdm。因此,您必须调用 tqdm.tqdm 来调用模块内的函数而不是模块本身。
回答by Kranthi Kumar Valaboju
You Have Used Only tqdm, Actually it is tqdm.tqdmSo, Try
你只用过 tqdm,实际上是tqdm.tqdm所以,试试
from tqdm import tqdm
for dir in tqdm(dirs, desc = 'dirs'):
print(dir)
回答by Yap
from tqdm import tqdm
with open(<your data>, mode='r', encoding='utf-8') as f:
for _, line in enumerate(tqdm(f)):
pass