selfteaching / selfteaching/selfteaching-python-camp

Day09 Counter的使用为什么要import collection?

Open
#788 0 comments 1 reaction 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.