python中文件夹想作为一个模块被引用,则在文件夹内必须要包含 __init__.py 文件,即使此文件为空。

如果此模块想要运行则必须要包含 __main__.py 文件。接下来说下两个文件起到的作用。

拿 robotframework 模块下的文件举例:

__init__.py里面一般包含了需要引用的模块

1 from robot.rebot import rebot, rebot_cli
2 from robot.run import run, run_cli
3 from robot.version import get_version

__all__ 参数意为导出包内模块,以下连接可以参考,不包含在__all__ 列表的模块不可被其他程序引用

此处 __version__ 应为一个系统定义的名字, 可在系统内引用

 from robot.rebot import rebot, rebot_cli
from robot.run import run, run_cli
from robot.version import get_version __all__ = ['run', 'run_cli', 'rebot', 'rebot_cli']
__version__ = get_version()

对于 __main__.py 我的理解是一个模块的入口函数执行模块

 import sys

 # Allows running as a script. __name__ check needed with multiprocessing:
# https://github.com/robotframework/robotframework/issues/1137
if 'robot' not in sys.modules and __name__ == '__main__':
import pythonpathsetter from robot import run_cli run_cli(sys.argv[1:])

当我们执行模块代码时首先会加载__init__.py 定义的引入模块,然后进入__mian__.py 文件运行

一下是运行模块的结果,调到了run_cli 的函数进行解析运行

E:\Software\Software\Python2.7.11\Lib\site-packages>python -m robot --help
Robot Framework -- A generic test automation framework

Version:  3.0 (Python 2.7.11 on win32)

Usage:  robot [options] data_sources
   or:  python -m robot [options] data_sources
   or:  python path/to/robot [options] data_sources
   or:  java -jar robotframework.jar [options] data_sources

。。。 。。。 。。。 。。。
Options
=======

-N --name name           Set the name of the top level test suite. Underscores
                          in the name are converted to spaces. Default name is
                          created from the name of the executed data source.
 -D --doc documentation   Set the documentation of the top level test suite.
                          Underscores in the documentation are converted to
                          spaces and it may also contain simple HTML formatting
                          (e.g. *bold* and http://url/).
 -M --metadata name:value *  Set metadata of the top level suite. Underscores
                          in the name and value are converted to spaces. Value
                          can contain same HTML formatting as --doc.

参考以下作者博客,敬谢:

https://www.cnblogs.com/alamZ/p/6943869.html

https://blog.zengrong.net/post/2192.html

最新文章

  1. react 犯错
  2. 学习EXT.JS5时的重点载图
  3. gulp插件(gulp-jmbuild),用于WEB前端构建
  4. MySQL迁移[转]
  5. AngularJS事件绑定的使用详解
  6. 折腾Ipython
  7. android 动态改变屏幕方向
  8. JAVA分布式事务原理及应用
  9. Centos 6.4 python 2.6 升级到 3.5.2
  10. Splunk
  11. 开发指南专题4:JEECG高速微云开发平台--JEECG开发环境的搭建
  12. ORA-00900: invalid SQL statement
  13. 032 Java再次总结
  14. MySQL文档翻译(八)附英文原文---性能优化概览
  15. 机器学习入门10 - 正则化:简单性(Regularization for Simplicity)
  16. 谁考了第k名
  17. Liferay7 BPM门户开发之12:acitiviti和liferay用户权限体系集成
  18. java计算器项目
  19. ios隐藏头部状态栏级tableview头部控件
  20. 【转】我为什么离开 Cornell

热门文章

  1. 解析JSON的两种方法eval()和JSON.parse()
  2. HBase资料
  3. parse_str 与 http_build_query的使用
  4. 如何把Excel中的单元格等对象保存成图片
  5. windows 下运行angualr/material2 项目
  6. Git与GitHub学习笔记(八)git如何同时同步提交到码云和GitHub上
  7. JavaScript 遍历多维数组
  8. HTML5本地存储应用sessionStorage和localStorage
  9. 固定表头,单元格td宽度自适应,多内容出现-横向纵向滚动条数据表格的<前世今生>
  10. form注册表单圆角 demo