selfteaching / selfteaching/selfteaching-python-camp
Day09 Counter的使用为什么要import collection?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 151
- Forks
- 875
- PR merge metrics
- No merged PRs in 30d
Description
看完参考材料,以为直接使用Counter对象就可以了,结果提示错误Undefined variable 'Counter',就是未定义Counter,这时候则需要在顶部 加上import collections,为什么要加上import collections?如果不同的库有同样的两个对象,会出现不知道取哪个的情况。比如我们现在的stats_word模块中,有re 库 和collections库,假如它们都有一个名为Counter的对象,你直接使用Counter的时候,会出现不知道你是取re库的Counter对象还是取collections库的Counter对象。如果没有这样import collections这个语句,就不能使用collections里面的函数对象方法。这是我的一点理解,如果不对请大家指正。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the referenced stats_word module and the lesson material discussing re, collections, and Counter. The issue does not name a documentation file or specify a requested change, so confirm the intended explanation and location with the maintainers before editing; done would mean an agreed clarification is added.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100