说明:本教程用图片+源码讲解Python常见的问题,共勉!
1.Python包的调用
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# coding:utf8 # from pakge.mymodel import test from bao.pakge.mymodel import test # 根据__init__.py检测包并存到环境变量里面,直接调用,不用管路径 mylist= [1,2,3] a = test(mylist) a.prt() a.tplt()
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import matplotlib.pyplot as plt class test(object): num = [] def __init__(self, _list): super(test, self).__init__() self.num = _list def prt(self): print(self.num) def tplt(self): plt.plot(self.num) plt.show() # mylist= [1,2,3] # a = test(mylist) # a.prt() # a.tplt()
注:Python根据__init__.py判断一个文件夹是不是包;__init__.py可以为空
2.Python