odd runtime error

Cameron Simpson cs at zip.com.au
Wed Dec 1 23:16:43 EST 2010


On 01Dec2010 17:27, David Brown <dmlb2000 at gmail.com> wrote:
| Thanks for the clarification

No worries.

| I like the idea of wrapping all the
| primary code in the script to a main function then calling it if its
| being called by main.

I find that useful too. I've got a few modules-that-implement-commands
that look like this:

  def main(argv):
    ... parse args, do stuff ...
    return exit_status

  ... functions, classes etc ...

  if __name__ == '__main__':
    sys.exit(main(sys.argv))

It seems fairly effective for keeping the top level logic up the top.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

It's better, when you're riding with someone you don't know so well, to stick
to the inside line - it's easier to avoid the bits...
        - Barry Sheene



More information about the Python-list mailing list