[Tutor] passing named arguments through command line
Robert Sokolewicz
r.sokolewicz at gmail.com
Thu Oct 30 15:01:51 CET 2014
I have a function with optional arguments x, y and I would like to pass y
or z using a named variable through the command line. Inside a python
script main(y=3) would work, but I have trouble passing y=3 as an argument
in command line.
I have tried the following:
----
import sys
def main(x=1, y=2):
print x
print y
if __name__ == '__main__':
main(*sys.argv[1:])
-----
from my terminal I get:
$ python script.py
1
2
$ python script.py y=3
y=3
2
whereas I would like the following to happen:
$ python script.py y=3
1
3
Is this doable in any convenient way?
thanks in advance!
-Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141030/bf1c18e2/attachment.html>
More information about the Tutor
mailing list