`

TypeError: 'module' object is not callable

阅读更多

自定义类,保存成Athlete.py文件

class Athlete:

def __init__(self, a_name, a_dob=None, a_times=[]):

self.name = a_name

self.dob = a_dob

self.times = a_times

在IDLE中调用

>>> import Athlete

>>> sarah = Athlete('Sarah Sweeney', '2002-6-17', ['1.58','2.02','2:56'])

报如下错误:

Traceback (most recent call last):

  File "<pyshell#2>", line 1, in <module>

    sarah = Athlete('Sarah Sweeney', '2002-6-17', ['1.58','2.02','2:56'])

TypeError: 'module' object is not callable

原因,没有导入类的路径

import Athlete

sarah = Athlete.Athlete('Sarah Sweeney', '2002-6-17', ['1.58','2.02','2:56'])

或者

from Athlete import Athlete

sarah = Athlete('Sarah Sweeney', '2002-6-17', ['1.58','2.02','2:56'])

分享到:
评论

相关推荐

    (241条消息)Python中报错“TypeError:‘list‘objectisnotcallable”的解决方法

    在Python编程过程中,可能会遇到一个常见的错误提示"TypeError: 'list' object is not callable"。这个错误通常是由于程序员不小心将内置的数据结构名称如`list`、`tuple`等作为变量名,导致后续尝试调用这些内置...

    Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法

    ### Python 出现错误 TypeError: ‘NoneType’ object is not iterable 解决办法 #### 错误概述 在Python编程过程中,经常会遇到各种类型的错误。其中,“TypeError: ‘NoneType’ object is not iterable”是一个...

    ngui中英文字符

    在游戏开发或者UI设计中,有时需要将中英文字符转换为位图字体,这涉及到图形渲染和字符编码。"ngui中英文字符"这个话题主要关注如何处理在NGUI(Unity引擎的一个用户界面系统)中生成包含中英文的位图字体。...

    笨办法学python 习题ex48 示例

    笨办法学pythoon 习题48 词汇扫描器代码 。 单元测试代码有微调。 常见错误 1. 'module' object has no attribute 'scan' ...3.TypeError: 'tuple' object is not callable 检查元组之间有没有漏加逗号

    自己编程中遇到的Python错误和解决方法汇总整理

    TypeError: 'int' object is not callable ``` **错误分析:** 使用`exec`执行字符串时,如果该字符串中包含了变量赋值操作,如`sqrt = 1`,则会改变当前作用域内的变量值。这导致原本指向`math.sqrt`函数的变量`...

    python如何爬取动态网站

    在使用selenium时,要注意一些常见问题,比如错误提示`TypeError: 'module' object is not callable`,这通常是由于导入语句错误导致的,正确的导入应该是`from selenium.webdriver import Chrome`或`from selenium....

Global site tag (gtag.js) - Google Analytics