<aside><nav><h2>Broker Reviews</h2>
<a href="https://www.binaryoptions.net/iq-option" title='IQ Option Review'>IQ Option</a> | <a href="https://www.binaryoptions.net/binary-com" title='Binary.com Review'>Binary.com</a> | <a href="https://www.binaryoptions.net/24option" title='24option Review'>24option</a> | <a href="https://www.binaryoptions.net/ayrex" title='Ayrex Review'>Ayrex</a>

For US traders: <a href="https://www.binaryoptions.net/nadex" title='Nadex Review'>Nadex</a>

<a href="https://www.binaryoptions.net/brokers/">List All Brokers</a>
</nav></aside>

python argparse: how to set “--version” “--help” confilct?

mabeljuhi
mabeljuhi Posts: 1 ✭
I have a python command programe, it has optional --version and --help argument. I want to set them confict each other. it means i can not type --help --version at the same time.

When i type ./demo --version --help it outputs the program's version infomation. When i type ./demo --help --version it outputs the program's help infomation.

I think this is weird,so i want to set then confict each other.

I tried the add_mutually_exclusive_group, but it makes no sense.

My program likes below:

#!python3
# -*- coding: utf-8 -*-
import argparse
parser = argparse.ArgumentParser()

parser.add_argument('-v', '--version', action='version',
version='%(prog)s 1.0', help="Show program's version number and exit.")
#parser.parse_args(['--version','--help'])
parser.parse_args(['--help','--version'])
Thanks very much!
Tagged:

Comments

In this Discussion