为什么无法从'collections'中导入'container'名称。
时间: 2023-12-26 12:04:28 浏览: 11
可能是因为你导入的是错误的名称。正确的导入语句应该是 `from collections import Container`,而不是 `from collections import container`。另外,需要注意的是,`Container`是一个抽象类,不能直接实例化,它只能作为其他集合类的基类来使用。
相关问题
无法从collections中导入iterable名称。
可能是因为您使用的Python版本不支持collections模块中的iterable名称。iterable名称在Python 2.6中引入,如果您使用的是Python 2.5或更早的版本,则无法使用该名称。
可以尝试升级您的Python版本,或者使用其他可替代的方法来完成您的任务。例如,您可以使用for循环来遍历集合中的元素,而无需使用iterable名称。
为什么用from collections import Container导入 collections 模块中的 Container 抽象类失败
如果你在使用 `from collections import Container` 导入 `collections` 模块中的 `Container` 抽象类时失败了,可能是因为你的 Python 版本较低,Python 2.x 版本中并没有 `collections.abc` 模块,因此也就没有 `Container` 抽象类。如果你使用的是 Python 2.x 版本,你可以使用 `from collections import Iterable` 来导入 `collections` 模块中的 `Iterable` 抽象类来判断一个对象是否可迭代。如果你使用的是 Python 3.x 版本,建议使用 `from collections.abc import Container` 来导入 `Container` 抽象类。