Created
December 16, 2012 15:56
-
-
Save anonymous/4308806 to your computer and use it in GitHub Desktop.
Python in 90 minutes, sample code
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"): | |
steps = 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