Skip to content

Instantly share code, notes, and snippets.

@st98
Last active August 29, 2015 14:06
Show Gist options
  • Save st98/95cb0e29533baa50a141 to your computer and use it in GitHub Desktop.
Save st98/95cb0e29533baa50a141 to your computer and use it in GitHub Desktop.
getopt。
import getopt
import sys
def usage(filename):
print('usage: python {} [-h | --help]'.format(filename))
def main(filename, *argv):
opts, args = getopt.getopt(argv, 'h', 'help')
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(filename)
return 0
return 0
if __name__ == '__main__':
sys.exit(main(*sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment