How about some syntactic sugar for " __name__ == '__main__' "?
Cameron Simpson
cs at zip.com.au
Thu Nov 13 02:23:57 EST 2014
On 12Nov2014 14:51, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor <ckaynor at zindagigames.com> wrote:
>> A decorator is an interesting idea, and should be easy to implement (only
>> lightly tested): [...]
>> Just decorate the "main" function of the script with that, and it will be
>> automatically called when ran as a script, but not when imported as a
>> module.
>
>This calls it at the wrong time, though. [...]
>This would call the main function at the time it's defined, when other
>things in the main script may not have been defined yet. One could
>place the main function last, but it would be preferable not to be
>forced.
Indeed. This aspect is a deal breaker for me; I'd never use it.
I make a point of putting the module's main function right up the top,
immediately after the imports and any "constants" (let's not dither over that
term). I _want_ the main function to in the reader's face when they visit the
module code. All the cogs come later.
And lots of my modules have "main" functions. Terribly useful.
Cheers,
Cameron Simpson <cs at zip.com.au>
We're in the business of putting goo on a substrate.
- overhead by WIRED at the Intelligent Printing conference Oct2006
More information about the Python-list
mailing list