为了账号安全,请及时绑定邮箱和手机立即绑定

对 main 的 Python 命令行调用不会进入 main 函数

对 main 的 Python 命令行调用不会进入 main 函数

猛跑小猪 2023-04-25 15:23:37
我有一个具有以下主要功能的 python 文件:if __name__ == '__main__':    args = docopt(__doc__)    print('source: %s' % args['--src'])    print('target: %s' % args['--tgt'])现在当我调用这个函数时:python test.py --src file1 --tgt file2我得到:Usage:    test.py --src=<file> --tgt=<file>Options:    -h --help            Show this screen.    --src=<file>         src    --tgt=<file>         tgt但是主要功能逻辑并没有被调用。如何解决这个问题?我试过:python test.py --src=file1 --tgt=file2但我得到了相同的结果。
查看完整描述

1 回答

?
慕无忌1623718

TA贡献1744条经验 获得超4个赞

检查你的文档字符串。Usage我认为问题是由于那里的部分和部分之间缺少换行符Options。


我试过这个文档字符串并且工作正常:


"""

Usage:

    test.py --src=<file> --tgt=<file>


Options:

    -h --help       Show this screen.

    --src<file>     src

    --tgt=<file>    tgt

"""

from docopt import docopt


if __name__ == '__main__':

    args = docopt(__doc__)

    print('source: %s' % args['--src'])

    print('target: %s' % args['--tgt'])


查看完整回答
反对 回复 2023-04-25
  • 1 回答
  • 0 关注
  • 84 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信