Making argument parsing easy
Project description
easyargs
A project designed to make command line argument parsing easy.
It is used as follows:
import easyargs
@easyargs
def main(name, count=1, greeting='Hello'):
"""A simple greeting program"""
for i in range(count):
print '{greeting} {name}!'.format(greeting=greeting, name=name)
if __name__ == '__main__':
main()
In this (rather contrived) example, main will be inspected and the arg keywords will be turned into positional arguments and the kwarg keywords will be turned into optional arguments. This can be seen if we run the above script with the help flag:
$ python simple.py -h
usage: simple_test.py [-h] [--count COUNT] [--greeting GREETING] name
A simple greeting program
positional arguments:
name
optional arguments:
-h, --help show this help message and exit
--count COUNT
--greeting GREETING
Note are that program description is automatically created based on the docstring of the function. Also note that the type of the default value is inspected so that the value of count is coerced to an integer:
$ python simple.py World
Hello World
$ python simple.py everybody --count 2 --greeting Hola
Hola everybody!
Hola everybody!
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
easyargs-0.8.2.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for easyargs-0.8.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2c83ff40fd47323b5c946466a8979afde9a1fb1bd6a1d6abea458ac43e233f8 |
|
MD5 | 87d17dbcdc8f6e3e9b0e358e864cbe87 |
|
BLAKE2b-256 | 103265fffff92cb22f035c68c075f57e7aee6c8f8b3773142c6a2e4d172a3e33 |