55

I import tqdm as this:

import tqdm

I am using tqdm to show progress in my python3 code, but I have the following error:

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)
4

4 回答 4

115

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.

于 2016-09-05T15:38:33.613 回答
9

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.

于 2019-06-28T17:32:54.573 回答
9

You Have Used Only tqdm, Actually it is tqdm.tqdm So, Try

from tqdm import tqdm

for dir in tqdm(dirs, desc = 'dirs'):
print(dir)
于 2020-03-29T03:00:52.450 回答
1
from tqdm import tqdm
with open(<your data>, mode='r', encoding='utf-8') as f:
    for _, line in enumerate(tqdm(f)):
       pass
于 2019-03-25T05:13:56.250 回答