我在doctopt脚本中使用了下面的args
Usage:
GaussianMixture.py --snpList=File --callingRAC=File
Options:
-h --help Show help.
snpList list snp txt
callingRAC results snp我想添加一个对我的脚本有条件结果的参数:更正我的数据或者不更正我的数据。类似于:
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 我想在我的脚本中添加一些函数中的if
def func1():
if args[correction] == 0:
datas = non_corrected_datas
if args[correction] == 1:
datas = corrected_datas但我不知道如何在用法中写它,我的脚本也不知道。
发布于 2016-12-07 17:10:30
编辑:我最初的答案没有考虑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)如果这对你有用,请告诉我。
发布于 2020-06-15 07:53:20
并非所有选项都必须在docopt中有参数。换句话说,您可以使用标志参数代替。这是从用户获取布尔值的最直接的方法。尽管如此,你可以简单地做以下几件事。
"""
Usage:
GaussianMixture.py (--correction | --no-correction)
Options:
--correction With correction
--no-correction Without correction
-h --help Show help.
"""
import docopt
if __name__ == '__main__':
args = docopt.docopt(__doc__)
print(args)https://stackoverflow.com/questions/41022532
复制相似问题