file
次のようなテストコードがあります。これは、位置引数またはすべてのオプション引数のいずれtime
かを取る必要がexpression
ありname
ます。
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-t","--time")
parser.add_argument("-x","--expression")
parser.add_argument("-n","--name")
parser.add_argument("file")
print parser.parse_args()
次の組み合わせが機能するはずです
test.py filename
test.py -t 5 -x foo -n test
しかし、これらではありません:
test.py filename -t 5 # should raise error because the positional and the optional -t argument cannot be used together
test.py -t 5 -x foo # should raise an error because all three of the optional arguments are required
その問題に対する簡単な解決策はありますか?