python3.6.1的unittest出错

2024-09-30 04:35:48 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我已经写了基本的python unittest代码如下:

import unittest

class Phonebooktest(unittest.TestCase):

   def test_create_phonebook():
       print("welcome to python")



if __name__ == '__main__':
    unittest.main()`

我收到一个错误:

^{pr2}$

有人请帮我解决这个错误。在


Tags: to代码testimportmaindef错误create
1条回答
网友
1楼 · 发布于 2024-09-30 04:35:48

很可能您的目录中有一个名为operator.py的文件。不幸的是,这个名称与Python的标准库冲突,后者有一个^{}模块。在

事实上,看看最后两行,其中一行说:

from operator import itemgetter as _itemgetter, eq as _eq
    ImportError: cannot import name 'itemgetter'

这意味着它试图从operator获取{},但是由于您的工作目录中有一个operator.py文件,它试图从该文件导入{},而不是Python的标准库。在

尝试将您的operator.py重命名为其他名称,然后看看会发生什么。在

相关问题 更多 >

    热门问题