selfteaching / selfteaching/selfteaching-python-camp

Day12 为什么返回None?(错误点在stats_text)

Open
#1,938 1 comment 0 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

#training.py

import requests
from wxpy import *
from pyquery import PyQuery
# 初始化机器人,扫码登陆
bot = Bot(cache_path=True)
@bot.register(Friend,SHARING)#对朋友发的sharing操作
def reply(msg):#注册函数:自动回复
    print(msg)
    #提取sharing正文
    response= requests.get(msg.url)
    document = PyQuery(response.text) 
    content = document('#js_content').text()
    from stats_word_d12 import stats_text
    result=str(stats_text(content))#调用模板,统计
    return result
embed()

#stats.py

import collections
import jieba
import re#导入正则表达式模块
def stats_text_cn(text):
    #提取中文字符串
    text= re.sub("[^\u4e00-\u9fa5]", "", text)#中文汉字unicode范围
    text=jieba.cut(text)#jieba精准模式分词
    found=[]
    for x in text:
        if len(x)>=2:
            found.append(x)
    return collections.Counter(found).most_common(10)

def stats_text_en(text):
    text= text.lower()
    text=re.sub("[^\\u0061-\u007a]", " ", text)
    text=text.split()   
    return collections.Counter(text).most_common(10)

def stats_text(text):
    stats_text_en(text)
    stats_text_cn(text)

@realcaiying 不发issue不告诉我的naughty教练

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 stats.py, then trace how stats_text is called from training.py. Check what value stats_text produces after invoking the English and Chinese helpers, and verify in the Day12 training flow that the returned result is displayed instead of None.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.