为什么我无法从回收模块中导入计数器? [处于保留状态]

问题描述 投票:-4回答:1

我当前使用的是python版本3.7,每次尝试从collections模块导入counter时,都会出现错误。

from collections import counter 
ImportError                               Traceback (most recent call 
last)
<ipython-input-34-8cabd9ed4f3e> in <module>
----> 1 from collections import counter

ImportError: cannot import name 'counter' from 'collections' 
(D:\python\lib\collections\__init__.py)

并且当我尝试通过使用collections.counter()手动进行操作时,它会告诉我“模块'collections'没有属性'counter'。我知道counter仅在2.7之后实现,但目前在3.7(如果我没记错的话,根据我的jupyter笔记本,我的python肯定至少在版本3上。任何帮助将不胜感激,因为这使我无法完成任务!

python python-3.x
1个回答
1
投票

使用from collections import Counter(注意大写字母C)

© www.soinside.com 2019 - 2024. All rights reserved.