当前位置:网站首页>采坑记录:TypeError: 'module' object is not callable
采坑记录:TypeError: 'module' object is not callable
2022-07-24 23:32:00 【GIS与Climate】
今天在改写代码的时候遇到如下报错:

TypeError: 'module' object is not callable
一开始找了好半天,代码确实没有写错:
pbar = tqdm(enumerate(train_loader), total=len(train_loader), desc='Train ')
就是一个很简单的语句。
后来debug了半天,看到参考链接【1】貌似才发现了什么,原来是导入方式写错了:
import tqdm
但是实际上如果用上面的方式来导入的话,需要用下面的方式来使用tqdm函数:
pbar = tqdm.tqdm(enumerate(train_loader), total=len(train_loader), desc='Train ')
但是多写几个字母多不方便,改成下面的导入方式就好了:
from tqdm import tqdm
为什么?
如果用import tqdm只不过是导入了tqdm这个模块,我们使用的是其中的函数,只不过恰巧这个函数名字与模块名相同而已。且这个模块中也不仅仅只有这一个函数!

经验
导入包的时候要规范; 使用包中的函数时候更是要规范!
参考
【1】https://blog.csdn.net/qq_36396104/article/details/82812461
边栏推荐
- Can Baidu network disk yundetectservice.exe be disabled and closed
- Effect evaluation of generative countermeasure network
- How painful is it to write unit tests? Can you do it
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 6
- 背景图和二维码合成
- Digital stopwatch based on Verilog HDL
- Value driven provides the core driving force for the transformation of commercial BP - BP realization under business scenarios - Commercial BP sharing
- 1、 MFC introduction
- Simple message queue implementation nodejs + redis =mq
- 如何创建和管理自定义的配置信息
猜你喜欢

ES6 adds -iterator traversal, for..Of loop

郑慧娟:基于统一大市场的数据资产应用场景与评估方法研究

Notes of Teacher Li Hongyi's 2020 in-depth learning series 7

2022 the most NB JVM foundation to tuning notes, thoroughly understand Alibaba P6 small case

Bug summary

Coding builds an image, inherits the self built basic image, and reports an error unauthorized: invalid credential Please confirm that you have entered the correct user name and password.

Understanding complexity and simple sorting operation

Convert a string to an integer and don't double it

生成式对抗网络的效果评估

What are the meanings and application scenarios of the three giants of cloud computing: IAAs, PAAS and SaaS?
随机推荐
Notes of Teacher Li Hongyi's 2020 in-depth learning series 4
Answers to some problems encountered in the process of Xperia XZ (f8332) brushing and root
Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
JS ------ Chapter 5 functions and events
Routing policy in republishing
On the problem that the on-board relay cannot be switched on due to insufficient power supply
Browser cache
MATLAB basic grammar (II)
郑慧娟:基于统一大市场的数据资产应用场景与评估方法研究
Processing PDF and JPG files in VB6
Effect evaluation of generative countermeasure network
Simple message queue implementation nodejs + redis =mq
Lidar obstacle detection and tracking: CUDA European clustering
ShardingSphere-数据库分库分表简介
Notes of Teacher Li Hongyi's 2020 in-depth learning series 8
必会面试题:1.浅拷贝和深拷贝_深拷贝
用VS Code搞Qt6:编译源代码与基本配置
Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge
Transmission download list, download file migration machine guide
生成式对抗网络的效果评估