-
-
Save larrycai/4308811 to your computer and use it in GitHub Desktop.
update the bug for passing parameter
This file contains hidden or 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/env python | |
""" | |
hello2.py hello world sample | |
Usage: hello2.py [options] | |
Options: | |
-m messages message list, separare by ',' | |
-h this help | |
Mail bug reports and suggestion to : Larry Cai <larry.caiyu AT gmail.com> | |
""" | |
import getopt, sys, os, errno | |
def helloworld(messages): | |
print messages | |
def main(): | |
message = "world" | |
try: | |
cmdlineOptions, args= getopt.getopt(sys.argv[1:],'hm:',["help","message="]) | |
except getopt.GetoptError, e: | |
raise "Error in a command-line option:\n\t" + str(e) | |
for (optName,optValue) in cmdlineOptions: | |
if optName in ("-h","--help"): | |
print __doc__ | |
sys.exit() | |
elif optName in ("-m","--message"): | |
message = optValue | |
else: | |
errorHandler('Option %s not recognized' % optName) | |
helloworld(message) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment