使用 python doctest 时出错
我尝试使用 http://docs.python.org/library/doctest 中的示例中的 doctest。 我
但是当我运行时
python example.py -v
得到了这个
Traceback (most recent call last):
File "example.py", line 61, in <module>
doctest.testmod()
AttributeError: 'module' object has no attribute 'testmod'
但是我可以在 python 交互式 shell 中导入 doctest 并启用使用 doctest.testmod() 。我在谷歌搜索并没有找到解决方案。
Max OSX 上的 Python 版本为 2.5.1
I try to use doctest from example from http://docs.python.org/library/doctest.html
But when I run
python example.py -v
I get this
Traceback (most recent call last):
File "example.py", line 61, in <module>
doctest.testmod()
AttributeError: 'module' object has no attribute 'testmod'
But I can import doctest in python interactive shell and enable to use doctest.testmod() as well. I searched in google and didn't find the solution.
Python version is 2.5.1 on Max OSX
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,此时您手头的 doctest 模块对象不是从标准库的
import doctest
中获得的正常的、纯粹的对象。在第 61 行之前打印doctest.__file__
(以及之后的sys.stdout.flush()
,只是为了确保您确实能够看到结果;-)异常会让你知道杂散的doctest
模块来自哪里。如果您向我们展示
example.py
以及该输出,我们可能会指出您到底做错了什么(如果您还没有意识到这一点)。Clearly the
doctest
module object you have at hand at that point is NOT the normal, unadulterated one you get from animport doctest
from the standard library. Printingdoctest.__file__
(andsys.stdout.flush()
ing after that, just to make sure you do get to see the results;-) before the line-61 exception will let you know WHERE that straydoctest
module is coming from.If you show us
example.py
as well as that output we can probably point out what exactly you may be doing wrong, if it doesn't already become obvious to you.尝试
在第 61 行之前插入一个。这将告诉您 doctest 模块的位置以及它具有哪些属性。您可以这样做以确保您的 doctest 模块没有任何问题。
Try inserting a
before line 61. This will tell you the location of the doctest module, and what attributes it has. You can do this to make sure that there's nothing wrong with your doctest module.