Created
December 24, 2014 07:25
-
-
Save haradreborn/3c7b320c2363eadeef10 to your computer and use it in GitHub Desktop.
Print args per option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys, getopt | |
def main(argv): | |
login = '' | |
password = '' | |
try: | |
opts, args = getopt.getopt(argv, "l:p", ["log=", "pas="]) | |
except getopt.GetoptError: | |
print 'test.py -l <login> -p <password>' | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print 'test.py -l <login> -p <password>' | |
sys.exit() | |
elif opt in ("-l", "--log"): | |
login = arg | |
elif opt in ("-p", "--pas"): | |
password = args[0] | |
print 'Login is "', login | |
print 'Password is "', password | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment