模块
例如这里有一个helpers.py文件
def display(message, is_warning=False):if is_warning:print('Warning')print(message)
在同级目录的文件中引用
import helpershelpers.display('not a warning')from helpers import * #一旦导入所有,模块中的所有东西就可以全局获取display('not a warning')from helpers import display #只导入需要的,唯一要注意的是导入的项是否有重名的情况display('not a warning')#三种没有区别,没有性能差异
包
包是被人已经发布的模块的集合
colorma可以在打印时改变文本颜色#安装pip install colorama#安装.txt文件中的包列表pip install -r requirements.txt#requirements.txtcolorama
保存当前环境安装的模块名和版本号信息
pip freeze > requirements.txt
