2024-09-30 04:35:48 发布
网友
嗨,我已经写了基本的python unittest代码如下:
import unittest class Phonebooktest(unittest.TestCase): def test_create_phonebook(): print("welcome to python") if __name__ == '__main__': unittest.main()`
我收到一个错误:
有人请帮我解决这个错误。在
很可能您的目录中有一个名为operator.py的文件。不幸的是,这个名称与Python的标准库冲突,后者有一个^{}模块。在
operator.py
事实上,看看最后两行,其中一行说:
from operator import itemgetter as _itemgetter, eq as _eq ImportError: cannot import name 'itemgetter'
这意味着它试图从operator获取{},但是由于您的工作目录中有一个operator.py文件,它试图从该文件导入{},而不是Python的标准库。在
operator
尝试将您的operator.py重命名为其他名称,然后看看会发生什么。在
很可能您的目录中有一个名为} 模块。在
operator.py
的文件。不幸的是,这个名称与Python的标准库冲突,后者有一个^{事实上,看看最后两行,其中一行说:
这意味着它试图从},但是由于您的工作目录中有一个},而不是Python的标准库。在
operator
获取{operator.py
文件,它试图从该文件导入{尝试将您的
operator.py
重命名为其他名称,然后看看会发生什么。在相关问题 更多 >
编程相关推荐