LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python: argument parsing (https://www.linuxquestions.org/questions/programming-9/python-argument-parsing-4175562677/)

PoleStar 12-30-2015 11:20 AM

python: argument parsing
 
I need to pass 3 arguments. like

Quote:

-c
-r
-g <some thing>
(-c and -r) is either or.
-g is a must with <some thing>

how that can be done?

Ztcoracat 12-30-2015 11:45 AM

These links might help:-

https://docs.python.org/2/library/argparse.html
https://docs.python.org/2/howto/argparse.html

Sorry I don't know more. I haven't finished reading the Python book yet.

PoleStar 12-30-2015 12:34 PM

Quote:

from optparse import OptionParser

parser = OptionParser()

parser.add_option("-c" , action="store_true" ,dest="check", help= "Only check" )
parser.add_option("-r" , action="store_true" ,dest="record", help= "Record data" )
parser.add_option("-g" ,dest="groupname", help= "Takes group name here" )

(options, args) = parser.parse_args()
This worked.

Thanks for the idea Ztcoracat.

Ztcoracat 12-30-2015 08:49 PM

Quote:

Originally Posted by PoleStar (Post 5470932)
This worked.

Thanks for the idea Ztcoracat.

You're Welcome-:)


All times are GMT -5. The time now is 03:54 AM.