An advanced parameter parser for Python.
Project description
Parameter Parser (Python)
Parameter Parser is a simple library used to parse intricate parameters from an array of strings.
Hint: This package is available through
Python PIP
.pip install parameterparser
Supports Python 2.7+
Documentation - Advanced Code Examples - Looking for the PHP version?
Features
- Parse command line parameters.
- Assign aliases to parameters.
- Custom closures for each command line parameter.
- Variadic closure support for arguments taking more than one value.
- Customize the way the command line is parsed.
Example Usage
import sys
from parameterparser import Parameter, Cluster, Parser
# Initialize a new Cluster
parameters = Cluster()
# Add a Parameter to the Cluster
parameter = Parameter("-", "name", lambda name: name)
parameter.set_required(True)\
.set_description("Your name.")
parameters.add(parameter)
# Create a new Parser using the Cluster
parser = Parser(sys.argv, parameters)
# Parse the parameters using the Parser.
results = parser.parse()
# Verify that the parameters were valid after parsing.
if not parser.is_valid():
# Since it was not valid, output usage.
parameters.print_full_usage(
"Parameter Parser",
"An advanced parameter parser for PHP",
"v1.0.0"
)
else:
# Retrieve the name from the results
name = results['name']
# Output the name
print("Your name is " . name . os.linesep)
Output
~/ python test.py -name 'Nathan Fiscaletti'
Your name is Nathan Fiscaletti
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
parameterparser-0.1.3.tar.gz
(8.9 kB
view hashes)
Built Distribution
Close
Hashes for parameterparser-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e465d8336a5b666d2ae596a039695456583c4e7b673768cebb9a96254a587bfd |
|
MD5 | 829b3a979b68a0922858ab53a20c83a4 |
|
BLAKE2b-256 | 785bd16f60e39a85d65022785bc37d9bd11f64c38b4d3a308b94af1010065b76 |