Python中的包和模块实例
一、实例和结果
1)实例的结构和具体的文件:
PyPackage │ PyCommonM.py │ __init__.py │ ├─p1Package │ P1M.py │ P1MC.py │ __init__.py │ └─p2 P2.py P2M.py
2)PyCommonM.py
defPyCommonMF(): print"PyCommonMF"
3)P1M.py:
defP1MF(): print'P1MF'
4)P1MC.py:
classP1MC(): @staticmethod defP1MCF(): print'P1MCF'
5)P2M.py:
defP2MF():print'P2MF'
6)P2.py:
importP2M fromPyPackageimportPyCommonM fromPyPackage.p1PackageimportP1M fromPyPackage.p1Package.P1MCimportP1MC
defP2F(): print'P2F' if__name__=='__main__': P2F() P2M.P2MF() P1M.P1MF() P1MC.P1MCF() PyCommonM.PyCommonMF()