我有一個(gè)具有以下主要功能的 python 文件:if __name__ == '__main__': args = docopt(__doc__) print('source: %s' % args['--src']) print('target: %s' % args['--tgt'])現(xiàn)在當(dāng)我調(diào)用這個(gè)函數(shù)時(shí):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但是主要功能邏輯并沒有被調(diào)用。如何解決這個(gè)問(wèn)題?我試過(guò):python test.py --src=file1 --tgt=file2但我得到了相同的結(jié)果。
1 回答

慕無(wú)忌1623718
TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
檢查你的文檔字符串。Usage我認(rèn)為問(wèn)題是由于那里的部分和部分之間缺少換行符Options。
我試過(guò)這個(gè)文檔字符串并且工作正常:
"""
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'])
添加回答
舉報(bào)
0/150
提交
取消