欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

'module' object has no attribute 'testmod' Python

shiping1 的头像

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

2011-12-04 22:20zzz8910199 | 分类:英语考试 | 浏览1136次
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 <module>
    doctest.testmod()
AttributeError: 'module' object has no attribute 'testmod'
 
2011-12-05 09:09提问者采纳
你的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了。
来自 http://zhidao.baidu.com/question/350818915.html
普通分类: