我遇到了一个非常奇怪的问题。我正在尝试在集合模块中使用计数器功能。但是,我不断收到相同的错误消息
AttributeError: 'module' object has no attribute 'Counter'
我之前尝试过使用它并且效果很好,但是现在由于某种原因,当我导入“集合”模块时,它的属性数量非常有限。
我试过了:
import collections # when calling Counter I would then use collections.Counter()
import collections as collect # collect.Counter()
对于这两个我不断收到属性错误。
我也试过
from collections import Counter
在这种情况下,我得到:
ImportError: cannot import name Counter
这些都在 ipython 界面和脚本中进行了测试(不导入其他任何东西,只是集合)。
有任何想法吗?
最佳答案
您应该使用新版本的 python AS python 3。然后您可以使用此模块。
然后导入,
import collections
from collections import counter
关于collections - 集合模块 Python 中的计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13311094/