2016-12-07 4 views
0

私はdoctoptdocoptブール引数パイソン

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 

を追加したいと思います。しかし、私は、使用中にも私のスクリプトでそれを記述する方法を知りません。任意の助け

おかげで

答えて

3

EDIT: 私のオリジナルの答えは必須であることを--correctionのアカウント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) 

この機能が動作するかどうかお知らせください。

+0

このソリューションをありがとう、これは動作します。しかし、私は本当に訂正の有無にかかわらず義務的な議論をしたいと思います。なぜなら、ユーザーはオプションの議論を忘れることができ、誤って訂正されないようなデータがあるからです。しかし、私は警告印刷を追加することができますが、私はより良い解決策を見つける:)とにかく感謝! – Elysire

+0

矯正義務(括弧を外す)を試して、真偽値を与えてみてください: –

+1

使用法: GaussianMixture.py --snpList =ファイル - 呼び出し元RAC =ファイル修正=(True | False) –