Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80670 > unrolled thread
| Started by | Cameron Simpson <cs@zip.com.au> |
|---|---|
| First post | 2014-11-13 18:23 +1100 |
| Last post | 2014-11-13 18:23 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How about some syntactic sugar for " __name__ == '__main__' "? Cameron Simpson <cs@zip.com.au> - 2014-11-13 18:23 +1100
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2014-11-13 18:23 +1100 |
| Subject | Re: How about some syntactic sugar for " __name__ == '__main__' "? |
| Message-ID | <mailman.15765.1415864451.18130.python-list@python.org> |
On 12Nov2014 14:51, Ian Kelly <ian.g.kelly@gmail.com> wrote: >On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor <ckaynor@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@zip.com.au> We're in the business of putting goo on a substrate. - overhead by WIRED at the Intelligent Printing conference Oct2006
Back to top | Article view | comp.lang.python
csiph-web