Skip to main content

Command line argument parsing library for python

Project description

Argument parsing for python developers

Usage:

import argument
f = argument.Arguments()
#Requried arguments, first argument will be stored as "candy"
f.required("candy", help="Candy name")
#optional value, set a default, can be changed by adding: --num=30, or -n=30
f.option("num",
    25,
    help="How many pieces?",
    abbr="n"
    )
#add a switch, a flag with no argument
f.switch("reverse",
    help="Reverse ordering",
    abbr="r"
)
#Process data before saving it
f.process("candy", lambda x: x.upper())

#get data
arguments, errors = f.parse()

Example:

python tests/demo.py bubblegum

{‘num’: 25, ‘reverse’: False, ‘candy’: ‘BUBBLEGUM’}

python tests/demo.py bubblegum -r -n=123

{‘num’: 123, ‘reverse’: True, ‘candy’: ‘BUBBLEGUM’}

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

argument-0.2.4.tar.gz (4.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page