On 12Nov2014 14:51, Ian Kelly <ian.g.ke...@gmail.com> wrote:
On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor <ckay...@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 <c...@zip.com.au>

We're in the business of putting goo on a substrate.
- overhead by WIRED at the Intelligent Printing conference Oct2006
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to