I'm a newbie to programming using python.
I have to create a script that ask for some argument.
So did this:
opts, args = getopt.getopt(argv[1:], "n:h", ["server-name=","help"])
for option, value in opts:
if option in ('-h', '--help'):
show_usage()
elif option in ('-n', '--server-name'):
serverName = value
evrithing it's OK:
./myscript -a www.site.com
BUT i'm asking how can i add this kind of argument
./myscript -a www.site.com -active=YES
getopt
expects the argument to be of the style --active=YES
. If you are happy with the double dash at the start (as shown) then you want to modify the first line of your code to be:
opts, args = getopt.getopt(argv[1:], "n:h", ["server-name=","help","active="])
and then add an appropriate conditional statement to your loop
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.