With docopt
it is easy.
Having docopt
installed:
$ pip install docopt
rewrite your solutions like this lookup.py
:
"""Usage: lookup.py <e-mail> <sender-ip>
Arguments:
<e-mail> e-mail address
<sender-ip> IP address
Sample use:
$ python lookup.py john.doe@example.com 1.2.3.4
"""
from docopt import docopt
if __name__ == "__main__":
args = docopt(__doc__)
attributeMap = {"e-mail": args["<e-mail>"], "sender-ip": args["<sender-ip>"]}
print attributeMap
and call from command line.
First to remember, how to call it (I choose positional arguments, you may use options too)
$ python lookup.py -h
Usage: lookup.py <e-mail> <sender-ip>
Arguments:
<e-mail> e-mail address
<sender-ip> IP address
Sample use:
$ python lookup.py john.doe@example.com 1.2.3.4
and finally see, how the dictionary you asked for gets populated:
$ python lookup.py john.doe@example.com 1.2.34
{'e-mail': 'john.doe@example.com', 'sender-ip': '1.2.34'}