Skip to content

Instantly share code, notes, and snippets.

@larrycai
Forked from anonymous/hello2.py
Created December 16, 2012 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larrycai/4308811 to your computer and use it in GitHub Desktop.
Save larrycai/4308811 to your computer and use it in GitHub Desktop.
update the bug for passing parameter
#!/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