如何导入模块_导入模块的作用_hello_dunder_双下划线
回忆上次内容
- 游乐场里面 已经有了一些函数
- help
- dir
- quit
- print
- 这些函数 位于 __builtins__ 模块
- 所以都是 内建函数
- 可以把 这个__builtins__删除掉吗?
删除结果
del __builtins__
导入 外部模块
- 导入命令 是
- import
- port是港口
- import 是进口 、 导入
- export 是出口 、 导出
- import 后面接空格
- 被导入的模块 是
- __hello__
- 读作 dunder hello
- 注意 hello 两边
import __hello__
变化
import
喊救命
help(__hello__)
观察模块
dir(__hello__)
引入模块的意义
- 我们可以通过
- 引入__hello__
- 引入 traceback
- 引入 time
- time模块里面有个asctime函数
- asctime 中的 asc 什么意思来着?
ascii
导入多个文件
反重力
观察LICENSE
vi /usr/lib/python3.8/LICENSE.txt
代码
- 尝试 加载
- 分词模块 jieba
- 词云模块 WordCloud
- 画图模块 matplotlib
import jieba
from wordcloud import WordCloud
import matplotlib.pyplot as plt
# 读取文件
with open('/usr/lib/python3.8/LICENSE.txt') as file:
text = file.read()
# 使用jieba进行中文分词
words = ' '.join(jieba.cut(text))
# 生成词云
wordcloud = WordCloud(font_path='/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', # 指定中文字体路径
width=800, height=600,
background_color='white').generate(words)
# 使用matplotlib展示词云
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()
新开窗口
:term
安装模块
pip install wordcloud
pip install matplotlib
pip install jieba
退出shell
运行
总结
- 模块 就是 封装好功能 的 部件
- 导入 __hello__ module模块
- 我想要做个 自己的模块
- 我们下次再说!
- 蓝桥->https://www.lanqiao.cn/courses/3584
- github->https://github.com/overmind1980/oeasy-python-tutorial
- gitee->https://gitee.com/overmind1980/oeasypython