On 10/25/07, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-10-25, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > > The canonical case for small scripts is to have first all > > functions and globals defined, then the main code protected by > > a guard, ie: > > There's no reason to "protect" your main code in a small script. >
There's also not much reason not to, and it prevents disaster or at least unwanted side effects when you accidentally run pychecker or pydoc over it. Also, debugging scripts is a lot easier when you can import them into a shell. > > if __name__ == '__main__': > > print SOME_CONST > > if not do_something(): > > try_somethin_else() > > That idiom is useful in modules for launching tests or examples > that should not be run when the module is imported. > I use it whenever there's any code I don't want run unless I'm explicitly trying to do so. -- http://mail.python.org/mailman/listinfo/python-list