A simple package for parsing function arguments from the command line
Project description
ParseArgs
A simple, intuitive way to parse command line arguments. Simply make a function, and call parseargs on it.
- parses data types through annoations (annotations not required for string arguments)
- parses optional keyword arguments by adding them as optional cli arguments
- parses positional arguments in a variable called arglist (so don't use that as a keyword!)
- adds a description of the command by using the signature of the method.
Example
in fun.py:
from parseargs import parseargs
def fun(firstname, lastname:str, number:int = 5):
print(f"Hello {firstname} {lastname}")
print(f"Your number is {number}")
number *= 2
print(f"Twice your number is {number}")
parseargs(fun)
Now on the command line, you can do:
$ python fun.py ricky bobby --number 5
Notice how it will print out 10. If you remove the annotation declaring the number an int, it will instead print out 55, because it will interpret it as a string.
We can get the method signature with:
$ python fun.py -h
usage: test2.py [-h] [--number NUMBER] arglist arglist
signature = (firstname, lastname: str, number: int = 5)
positional arguments:
arglist
optional arguments:
-h, --help show this help message and exit
--number NUMBER
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
parseargs-0.0.4.tar.gz
(2.2 kB
view hashes)
Built Distribution
Close
Hashes for parseargs-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba7720ce826b027248699b4e28f639067c9cf706d0a593cc456355f45d50704b |
|
MD5 | 852439eb49f865e34827f23972ecaf67 |
|
BLAKE2b-256 | 4f26718baea6efd81e8bb0a17277e9854ebcfb5341b25359076b8acc48c4cf98 |