使用sphinx记录python脚本条目(__name__ =='__main__') [英] Documenting python script entry (__name__ == '__main__') using sphinx

查看:201
本文介绍了使用sphinx记录python脚本条目(__name__ =='__main__')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法,理想地使用 autodoc ,来获取狮身人面像来记录一个Python脚本?我想要记录的脚本部分是受以下保护的部分:

 如果__name__ =='__main__':

ie这个位只有在模块用作脚本而不是导入时才会运行。

解决方案

你应该提取代码阻止一个函数,使用一个docstring,并从块中调用该函数。


Is there a way, ideally using autodoc, to get sphinx to document a Python script? The section of the script I want documented is the portion protected by:

if __name__ == '__main__':

i.e. the bit that only runs if the module is used as a script instead of being imported.

解决方案

You should extract the code in that block into a function, with a docstring, and call that function from the block.

这篇关于使用sphinx记录python脚本条目(__name__ =='__main__')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆