An automatic handling of parameter passing to python programs.
Project description
parapy
An automatic handling of parameter passing to python programs
Usage
Import the script. Then in the top of your own document, define a list of tuples of all your parameters of the form ('name', 'prefix'/position, type), and then call the library using params.params(Your_Parameters). This will return a dictionary of all the parameters of the form {'name' : value}.
The library supports prefixed parameters (i.e. whatever comes after '-i'), boolean parameters (i.e. if '-a' is passed) and positional parameters (i.e. the second parameter without a prefix).
Currently supported types are str, int, float and bool. Multi-word parameters must be enclosed in quotes.
Example
import params
parameters = [('output', '-o', str), # A string parameter with prefix '-o'
('amount', '-n', int), # An integer parameter with prefix '-n'
('verbose', '-v', bool), # A boolean parameter with name '-v'
('eggs', '-e', float), # A float parameter with prefix '-e'
('input', 0, str), # A string parameter position 0
('spam', 1, int), # An integer parameter position 1
('message', '-m', str)] # A string parameter with prefix '-m'
p = (params.params(parameters))
print(p)
Then calling the program with the parameters as such: python program.py -v gov_secrets.db -o elvis.mp3 4 -n 10 -m "Listen to this cool track!", will result in the following output:
{'output': 'elvis.mp3',
'amount': 10,
'verbose': True,
'eggs': None,
'input': 'gov_secrets.db',
'spam': 4,
'message': 'Listen to this cool track!'}
TODO
- Add default values
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parapy-0.0.3.tar.gz.
File metadata
- Download URL: parapy-0.0.3.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a339f2480806e883beefa789002d3e6a3007c9f2266e550c98e1054f2ea8170d
|
|
| MD5 |
1588d2ccc780c4faa027e5d5ae44ae5d
|
|
| BLAKE2b-256 |
9b802410b219da9280bf3f37bcb1b6b76209745f24e2e44b021dcea32d37e30a
|
File details
Details for the file parapy-0.0.3-py3-none-any.whl.
File metadata
- Download URL: parapy-0.0.3-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b4a270276ffe6ebcbd8560692cadb1fec3ed9c6e9755a52d5f1aec553e9c3bf
|
|
| MD5 |
9f7e89154d1d5e0ae5d897e18c1e28c6
|
|
| BLAKE2b-256 |
fe1cc60df7660e1f253517d5936172b1c205e8c3ee44f692a609f20feaf35c20
|