我在 doctopt 脚本中使用以下参数
Usage:
GaussianMixture.py --snpList=File --callingRAC=File
Options:
-h --help Show help.
snpList list snp txt
callingRAC results snp
Run Code Online (Sandbox Code Playgroud)
我想添加一个对我的脚本有条件结果的参数:更正我的数据或不更正我的数据。就像是 :
Usage:
GaussianMixture.py --snpList=File --callingRAC=File correction(--0 | --1)
Options:
-h --help Show help.
snpList list snp txt
callingRAC results snp
correction 0 : without correction | 1 : with correction
Run Code Online (Sandbox Code Playgroud)
我想在我的脚本中添加if一些函数
def func1():
if args[correction] == 0:
datas = non_corrected_datas
if args[correction] == 1:
datas = corrected_datas
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在用法中编写它,也不知道如何在我的脚本中编写它。
编辑: 我原来的答案没有考虑OP的强制要求。我原来的答案中的语法不正确。这是一个经过测试的工作示例:
#!/usr/bin/env python
"""Usage:
GaussianMixture.py --snpList=File --callingRAC=File --correction=<BOOL>
Options:
-h, --help Show this message and exit.
-V, --version Show the version and exit
--snpList list snp txt
--callingRAC results snp
--correction=BOOL Perform correction? True or False. [default: True]
"""
__version__ = '0.0.1'
from docopt import docopt
def main(args):
args = docopt(__doc__, version=__version__)
print(args)
if args['--correction'] == 'True':
print("True")
else:
print("False")
if __name__ == '__main__':
args = docopt(__doc__, version=__version__)
main(args)
Run Code Online (Sandbox Code Playgroud)
请告诉我这是否适合您。