docopt布尔arg python

2024-05-16 13:10:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我在docopt中为脚本使用以下参数

Usage:
GaussianMixture.py --snpList=File --callingRAC=File

Options:
-h --help     Show help.
snpList     list snp txt
callingRAC      results snp

我想添加一个对脚本有条件结果的参数:correct my datas or don't correct my datas。比如:

^{pr2}$

我想在我的脚本中添加一个if在一些函数中

def func1():
  if args[correction] == 0:
      datas = non_corrected_datas
  if args[correction] == 1:
      datas = corrected_datas

但是我不知道怎么写,也不知道怎么写。在

谢谢你的帮助


Tags: 脚本参数ifmyhelpargsdocoptfile
1条回答
网友
1楼 · 发布于 2024-05-16 13:10:34

编辑: 我最初的回答并没有考虑到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)

请告诉我这对你是否有用。在

相关问题 更多 >