Revisions
-






25a99a
jeremyb...
Mon Sep 07 00:05:02 -0700 2009
-






4b8cd4
jeremyb...
Sun Sep 06 03:26:45 -0700 2009
-






776b2c
jeremyb...
Sun Sep 06 02:28:34 -0700 2009
-






a33053
jeremyb...
Sun Sep 06 02:26:49 -0700 2009
-






811e99
jeremyb...
Sun Sep 06 02:24:38 -0700 2009
-






11dec7
jeremyb...
Sun Sep 06 02:16:47 -0700 2009
-






51421c
jeremyb...
Sun Sep 06 02:10:01 -0700 2009
-






45d3d6
jeremyb...
Sun Sep 06 01:47:10 -0700 2009
-






cb15b5
jeremyb...
Sun Sep 06 00:54:31 -0700 2009
Every gist with this icon (
Every repository with this icon (
This is a template intended for use as the starting point of simple
command-line Python scripts. It wraps the main function, passing on
the arguments the script was called with and using the function's
return value as the exit code. If an invalid number of arguments are
provided, it generates and displays a usage string from the function's
argument list and docstring.
Here are some examples that should demonstrate exactly how this works.
def main():
pass
$ ./hello.py too many arguments
usage: ./hello.py
With an argument:
def main(directory):
pass
$ ./something.py too many arguments
usage: ./something.py directory
With a default argument:
def main(name, age=None):
pass
$ ./add_member.py # no arguments
usage: ./add_member.py name [age]
With only default arguments:
def main(subject="all", verbosity=0):
pass
$ ./help.py # no arguments
usage: ./help.py [subject [verbosity]]
With a docstring and capturing extra arguments:
def main(no, more, contrived=None, *examples):
"""I promise."""
pass
$ ./example.py yes
usage: ./example.py no more [contrived [examples...]]
I promise.
If so inclined anyone may use this for any purpose so long as I'm not responsible if something somehow goes wrong. Letting me know that you're using it would be appreciated, but isn't required.
Author: Jeremy Banks <jeremy@jeremybanks.ca>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|


