Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tqdm: 'module' object is not callable

Tags:

python

tqdm

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) 
like image 481
Zhao Avatar asked Sep 05 '16 02:09

Zhao


People also ask

What is tqdm () in Python?

tqdm is a library in Python which is used for creating Progress Meters or Progress Bars. tqdm got its name from the Arabic name taqaddum which means 'progress'. Implementing tqdm can be done effortlessly in our loops, functions or even Pandas.

How do I run a tqdm in Python?

Using tqdm is very simple, you just need to add your code between tqdm() after importing the library in your code. You need to make sure that the code you put in between the tqdm() function must be iterable or it would not work at all.

What does tqdm stand for?

tqdm derives from the Arabic word taqaddum (تقدّم) which can mean “progress,” and is an abbreviation for “I love you so much” in Spanish (te quiero demasiado).

What is tqdm range?

Ranges from 0 (average speed) to 1 (current/instantaneous speed) [default: 0.3].


2 Answers

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.

like image 89
idjaw Avatar answered Sep 18 '22 21:09

idjaw


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.

like image 22
Jake Avatar answered Sep 19 '22 21:09

Jake