about functions question

Neil Cerutti horpner at yahoo.com
Fri Oct 26 14:22:56 CEST 2007


On 2007-10-26, Bruno Desthuilliers <bruno.42.desthuilliers at wtf.websiteburo.oops.com> wrote:
> Neil Cerutti a écrit :
>> On 2007-10-25, Bruno Desthuilliers
>> <bruno.42.desthuilliers at wtf.websiteburo.oops.com> 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.
>
> I actually have at least one: it allow me to execute all the
> top-level definitions in Emacs' Python sub-interpreter buffer
> for testing, without actually executing the 'main' code.
>
>>> if __name__ == '__main__':
>>>    print SOME_CONST
>>>    if not do_something():
>>>      try_somethin_else()
>> 
>> That idiom is 
>
><insert>also</insert>
>
>> useful in modules for launching tests or examples
>> that should not be run when the module is imported.
>> 
> Indeed.

Thanks to you and Chris for giving me the tool-related
applications of that idiom. I haven't used the associated tools.

-- 
Neil Cerutti
Ushers will eat latecomers. --Church Bulletin Blooper



More information about the Python-list mailing list