本篇文章给大家分享的是有关怎么在python中利用Package设置文件入口,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
成都创新互联公司主营黄山区网站建设的网络公司,主营网站建设方案,app软件开发公司,黄山区h5微信小程序定制开发搭建,黄山区网站营销推广欢迎黄山区等地区企业咨询
Python主要应用于:1、Web开发;2、数据科学研究;3、网络爬虫;4、嵌入式应用开发;5、游戏开发;6、桌面应用开发。
1、说明
(1)Python 中的包(Package)则是模块的文件夹,往往由 __init__.py 指明某个文件夹为包;
(2)Package可以为某个目录下所有的文件设置统一入口。
2、实例
someDir/ main.py subModules/ __init__.py subA.py subSubModules/ __init__.py subSubA.py # subA.py def subAFun(): print('Hello from subAFun') def subAFunTwo(): print('Hello from subAFunTwo') # subSubA.py def subSubAFun(): print('Hello from subSubAFun') def subSubAFunTwo(): print('Hello from subSubAFunTwo') # __init__.py from subDir # Adds 'subAFun()' and 'subAFunTwo()' to the 'subDir' namespace from .subA import * # The following two import statement do the same thing, they add 'subSubAFun()' and 'subSubAFunTwo()' to the 'subDir' namespace. The first one assumes '__init__.py' is empty in 'subSubDir', and the second one, assumes '__init__.py' in 'subSubDir' contains 'from .subSubA import *'. # Assumes '__init__.py' is empty in 'subSubDir' # Adds 'subSubAFun()' and 'subSubAFunTwo()' to the 'subDir' namespace from .subSubDir.subSubA import * # Assumes '__init__.py' in 'subSubDir' has 'from .subSubA import *' # Adds 'subSubAFun()' and 'subSubAFunTwo()' to the 'subDir' namespace from .subSubDir import * # __init__.py from subSubDir # Adds 'subSubAFun()' and 'subSubAFunTwo()' to the 'subSubDir' namespace from .subSubA import * # main.py import subDir subDir.subAFun() # Hello from subAFun subDir.subAFunTwo() # Hello from subAFunTwo subDir.subSubAFun() # Hello from subSubAFun subDir.subSubAFunTwo() # Hello from subSubAFunTwo
以上就是怎么在python中利用Package设置文件入口,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。