Skip to main content

addition types to use with argparse

Project description

argparse_types

Special argparse types

How to install

pip install argparse-types

description

Additional types to use with argparse

how to use

Import argparse_types pass the argparse_types."type" to the type keyword in argparse.add_argument. Remember to pass not to call.

example.py

import argparse

import argparse_types


parser = argparse.ArgumentParser()
parser.add_argument("-n", dest="number", type=argparse_types.pos_int)
args = parser.parse_args()
print(args.number)

python3 example.py -n 34

34

python3 example.py -n -34

example.py: error: argument -n: -34 is an invalid positive int value

types

  • pos_int - Positive int value not including 0
  • neg_int - Negative int value not including 0
  • zero_int - Zero int value
  • pos_float - Positive float value not including 0
  • neg_float - Negative float value not including 0
  • zero_float - Zero float value
  • int_float - Any int or float value
  • bool_none - True, False, None value
  • ip4 - ip address 0.0.0.0 to 255.255.255.255 not including port

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argparse_types-0.2.0.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

argparse_types-0.2.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page