鱼C论坛

 找回密码
 立即注册
查看: 1969|回复: 0

[技术交流] 关于之前《正确展示用代码吃王力宏的瓜》帖子里的代码几点疑问

[复制链接]
发表于 2022-3-4 16:50:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
原贴在这:
正确展示用代码吃王力宏的瓜
https://fishc.com.cn/thread-207059-1-1.html
(出处: 鱼C论坛)

帖子里有个附件,是吃瓜的源码,对于这个源码我有几个不理解的地方,希望大神能帮忙解读下

comment_show.py这文件里的代码中的这一段应该都是在将爬取的评论分词吧:
  1. stop_words = []
  2. with open('stop_words.txt', 'r', encoding='utf-8') as f:
  3.     lines = f.readlines()
  4.     for line in lines:
  5.         stop_words.append(line.strip())
  6. content = open('comments.txt', 'rb').read()
  7. # jieba 分词
  8. word_list = jieba.cut(content)
  9. words = []
  10. for word in word_list:
  11.     if word not in stop_words:
  12.         words.append(word)

  13. wordcount = {}
  14. for word in words:
  15.     if word != ' ':
  16.         wordcount[word] = wordcount.get(word, 0)+1
复制代码

1、上面代码中第2行:stop_words.txt文件是哪里来的?没有在代码中找到有创建这个文件呐?

2、第6行代码中,comments.txt是存放爬取到的评论的文件,这里为什么要用二进制去打开它?用只 ‘r’ 读模式不行吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-20 10:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表