selfteaching / selfteaching/selfteaching-python-camp

Day12 使用wxpy过程中@bot.register()和import *的问题

Open
#1,169 0 comments 3 reactions 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

1. 关于装饰器
在监听好友消息并回复分析处理后结果的学习中,有一段示例代码:

@bot.register(Group, TEXT)
def print_group_msg(msg):
    print(msg)

这里出现了一个用法为 @bot.register() ,之前的教程中尚未涉及到这一部分,后来翻看了笑来老师的书,其中讲到了装饰器。
@bot.register() 在python中这种语法被称为装饰器(decorator)。它的作用是将 print_group_msg()函数当做一个参数传给bot.register()函数。

更多详细内容,可以参考笑来老师书中的装饰器章节:
https://github.com/selfteaching/the-craft-of-selfteaching/blob/master/Part.3.B.3.decorator-iterator-generator.ipynb

2. 关于import... 和 from...import...
今天的作业中,如果直接使用 from wxpy import * , 会提示异常如下:
image

这是因为导入的模块中,很多子类没有用到,但这并不影响程序的运行。
如果想去掉这些异常的提示,可以使用
from wxpy import Bot,Message,embed , 只导入用到的类和方法。

另外,还可以直接使用 import wxpy ,但在使用其中的子类和方法时,都必须增加wxpy.前缀。

以上描述如果有错误还请大家指正,对这些问题同样有疑问的也欢迎一起交流 😄 。

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 with the Day12 wxpy lesson and the referenced Part.3.B.3.decorator-iterator-generator.ipynb notebook, then compare the decorator and import explanations with the examples in this issue. Done means the lesson clearly explains @bot.register() and the supported import forms, including the reported warning behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.