[Chicago] __name__ == "__main__"
Dave Niesman
dave.niesman at ieee.org
Sat Oct 27 00:44:54 CEST 2007
If we are showing our dirty laundry...
import sys
from optparse import OptionParser
def ValidateArgs(argv):
"""
validate command line arguments
"""
success = True
parser = OptionParser()
parser.add_option("-e", "--echo",
action = "store_true",
dest="echo",
help="echo back the command line arguments")
options, args = parser.parse_args(argv)
return success, options, args
def main(argv=None):
"""
Testable main function
Usage:
main() - use arguments from sys.argv
main(["main.py", 1, 2, 3 "34"]) - provide arguments for test
"""
if argv is None :
argv = sys.argv[1:]
success, options, args = ValidateArgs(argv)
if success:
if options.echo:
i = 0
for theArg in args:
i += 1
print "argv[" + str(i) + "]: " + theArg
if __name__ == '__main__' :
sys.exit(main())
On 10/26/07, skip at pobox.com <skip at pobox.com> wrote:
>
>
> Me as well. When I have my thinking cap on I start with this:
>
...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/chicago/attachments/20071026/235ffa06/attachment.htm
More information about the Chicago
mailing list