作业帮 > 综合 > 作业

'module' object has no attribute 'testmod' Python求助

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/06/22 22:50:53
'module' object has no attribute 'testmod' Python求助
def f2c(t):
"""
>>>f2c(212)
100
>>>f2c(32)
0
>>>f2c(-40)
-40
>>>f2c(36)
2
>>>f2c(37)
3
>>>f2c(38)
3
>>>f2c(39)
4
"""
s = float((int(t)-32)*5)/9
print int(round(s))
if __name__ == '__main__':
import doctest
doctest.testmod()
它返回了
Traceback (most recent call last):
File "F:\text\计算机导论\python\1204.8.py", line 23, in
doctest.testmod()
AttributeError: 'module' object has no attribute 'testmod'
'module' object has no attribute 'testmod' Python求助
你的doctest是不是被改过了?
再问: 我不太清楚,那怎么样查看,怎么样把它改回去呢?
再答: 标准库里的doctest是肯定有testmod的,你看看你import doctest之后doctest.__file__是什么
再问: 'F:\\text\\\xbc\xc6\xcb\xe3\xbb\xfa\xb5\xbc\xc2\xdb\\python\\doctest.pyc' 是这一串
再答: 因为你的1204.8.py文件同一目录下有了一个叫doctest的,所以python在import doctest的时候就import你这个了,所以你没有import到标准库里的doctest,你可以把你的1204..8.py换到一个没有doctest.py的目录,或者把你的“F:\text\计算机导论\python\”目录里的doctest.py和doctest.pyc给删掉,就可以import到标准库里的doctest了。