python3 模块和包
2019-12-02 本文已影响0人
SkTj
pip用法:需要增加
导入模块
import random
from random import random
from random import *
打印传参
![](https://img.haomeiwen.com/i9967595/0fa7cd9cbec1f85c.png)
打印操作系统相关
![](https://img.haomeiwen.com/i9967595/b103f0a4f179bf23.png)
自定义模块
![](https://img.haomeiwen.com/i9967595/ef6db71c63bd7239.png)
from .module1 import *
name
![](https://img.haomeiwen.com/i9967595/1e374e88e34dc2ad.png)
python加载模块来自三个地方:
环境变量:PYTHONPATH
默认模块路径(包括当前目录)
![](https://img.haomeiwen.com/i9967595/a929e33c603b15bb.png)
多个文件组成一个包 init.py
![](https://img.haomeiwen.com/i9967595/56f21cb67d2f3b99.png)
导入所有包内成员
![](https://img.haomeiwen.com/i9967595/ad834976d248b2d6.png)
调用
![](https://img.haomeiwen.com/i9967595/fd09e4dfeb1873ba.png)