首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在接受命令行args的脚本上使用pdoc?

如何在接受命令行args的脚本上使用pdoc?
EN

Stack Overflow用户
提问于 2019-10-29 15:10:39
回答 1查看 1.1K关注 0票数 1

我试图使用pdoc来记录我的python脚本,但是由于我的程序需要使用命令行args,所以我遇到了一个问题。

我的程序名为:myprogram.py -p arg1 -s arg2

我试着按以下方式运行pdoc:pdoc --html myprogram

但我说pdoc: error: the following arguments are required: -p时出错了

但是,如果我尝试像这样运行pdoc:pdoc --html myprogram.py -p arg1 -s arg2,则会得到以下错误:

pdoc: error: unrecognized arguments: -p arg1 -s arg2

有办法在需要命令行args的模块上运行pdoc吗?

EN

回答 1

Stack Overflow用户

发布于 2020-04-15 17:57:27

pdoc the documented modules开始,您需要在main guard下嵌套CLI程序执行。

代码语言:javascript
复制
def main():
    from argparse import ArgumentParser
    parser = ArgumentParser(...)
    args = parser.parse_args()
    ...

if __name__ == '__main__':
    # Run main entry point only if the script was run as a program
    # and not if it was merely imported
    main()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58610226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档