Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 属性错误:';模块';对象没有属性';testmod';Python博士测试_Windows_Macos_Python 2.7_Doctest - Fatal编程技术网

Windows 属性错误:';模块';对象没有属性';testmod';Python博士测试

Windows 属性错误:';模块';对象没有属性';testmod';Python博士测试,windows,macos,python-2.7,doctest,Windows,Macos,Python 2.7,Doctest,当我尝试用python进行doctest时,基本上是在我运行代码时 if __name__ =="__main__": import doctest doctest.testmod() 我从翻译那里得到了这个回答 AttributeError:“模块”对象没有属性“testmod” 我可以很好地运行这段代码,但每当我在我的windows机器上运行它时,它就不起作用了 我的机器运行的是Windows操作系统X,但运行的是python 2.7.5 谢谢:)看起来有一个名为doctest

当我尝试用python进行doctest时,基本上是在我运行代码时

if __name__ =="__main__":
   import doctest
   doctest.testmod()
我从翻译那里得到了这个回答

AttributeError:“模块”对象没有属性“testmod”

我可以很好地运行这段代码,但每当我在我的windows机器上运行它时,它就不起作用了

我的机器运行的是Windows操作系统X,但运行的是python 2.7.5


谢谢:)

看起来有一个名为
doctest
的不同模块正在导入,而不是标准模块

要准确了解导入的模块,只需添加以下
print

if __name__ =="__main__":
   import doctest
   print doctest.__file__  # add this
   doctest.testmod()
根据您使用的Python的位置和版本,
print
应该生成类似于
C:\Python27\lib\doctest.pyc
。任何其他输出都表示您导入了错误的模块,并解释出现错误的原因

AttributeError
:“module”对象没有属性“testmod”

显然,您要导入的
doctest
模块没有
testmod()
方法

可能的原因包括:

  • lib
    中有多个
    doctest
    模块
  • 并且,它是另一个(没有
    testmod()
    方法)作为
    import doctest
    的结果被导入的

解决方案:查找标准
doctest
模块的路径

if __name__ =="__main__":
   import doctest
   if doctest.__file__  == "/path/to/standard/doctest-module":
       doctest.testmod()

确保您没有试图将测试文件保存为
doctest.py
。上面建议的打印语句将显示它。如果文件名为
doctest.py
,请重命名它并重试