Python TypeError: 'module' object is not callable 详解
2017-10-28 21:06
726 查看
问题背景
创建了一个Read_Capacity.py文件,其中有一个同名的类Read_Capacity( ),我希望导入这个模块,创建一个该类的实例对象,调用其中的类方法以及访问类变量。结果显示:
Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'module' object is not callable
原因分析
Python导入模块的方法有两种,import module 和 from module import ,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。解决方法
使用 import module,注意加上模块名即可>>> import Read_Capacity >>> rc = Read_Capacity.Read_Capacity()
或者,使用 from module import class name,当这个模块中包含许多类时,如果需要使用到这个模块的许多类,那么可以用 from module import *。
>>> from Read_Capacity import Read_Capacity >>> rc = Read_Capacity()
有关python模块的使用方法,可以参考文档:https://docs.python.org/2/tutorial/modules.html
相关文章推荐
- python错误TypeError: 'module' object is not callable 的解决方法
- Python导入模块(包)的两种方式 TypeError: 'module' object is not callable
- 【Python】TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析(python模块导入注意事项)
- 【Python】TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- python错误TypeError: 'module' object is not callable 的解决方法
- TypeError: 'module' object is not callable 原因分析
- python错误TypeError: 'module' object is not callable 的解决方法
- Python TypeError: 'module' object is not callable
- python+selenium自动化测试~打开浏览器报TypeError: 'module' object is not callable
- Python包导入(TypeError: 'module' object is not callable),及一定要记住Python成员函数第一个参数值是self。
- python 报错——Python TypeError: 'module' object is not callable 原因分析
- python import 错误 TypeError: 'module' object is not callable
- TypeError: 'module' object is not callable 原因分析
- python3学习笔记1--TypeError: 'dict' object is not callable的解决
- TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析