Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61588

Re: Is there any advantage to using a main() in python scripts?

Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.054
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; 'language.': 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'locating': 0.16; 'referencing': 0.16; 'stuff.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'thu,': 0.19; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'first,': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'classes': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'possible': 0.36; 'subject:?': 0.36; 'should': 0.36; 'two': 0.37; 'starting': 0.37; '12,': 0.39; 'even': 0.60; 'helps': 0.61; 'matter': 0.61; 'first': 0.61; 'subject:there': 0.68; 'me).': 0.84; 'recursion,': 0.84; 'to:none': 0.92; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=M5UdGKIhhsG1tO5SXm5tZUWIggEuWipqM6RjBbU4NWU=; b=IL/Z9Nq988i/fYPW93AQCV61UgMwifXkhxT1IAduKSy6AQNEsfHnWjSDwX8TdZAjEZ 3B8lUxIQ0KqnbXemralSn+aVgJL0dlrQCzLlZ76Sp4CqK/5d4vhqPRuzg4yATuHmLX38 0FHRndw/keyF2GLZwbLs52JxHqjwhOmcbxVpQfLqssWx1oFuOPuR2vvX1x3Alj9H0t/O 4uusCr8Ydv4vb9rphMvIQy87KYWxkVIpCmLi2uRx11tgTHLAiURwcyWHvp+POk7TkCcH vR53mSpiN/vKmAGjhP7XdPNle3bYpdMUJN86aBzqtIt56t3piDekL5zMPO9RXXDfJpY2 jj1g==
MIME-Version 1.0
X-Received by 10.68.248.33 with SMTP id yj1mr2426936pbc.45.1386776964065; Wed, 11 Dec 2013 07:49:24 -0800 (PST)
In-Reply-To <52A887DB.6030600@gmail.com>
References <32615c9a-b983-4399-bb55-6df6c230f247@googlegroups.com> <52A887DB.6030600@gmail.com>
Date Thu, 12 Dec 2013 02:49:23 +1100
Subject Re: Is there any advantage to using a main() in python scripts?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3906.1386776974.18130.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386776974 news.xs4all.nl 2901 [2001:888:2000:d::a6]:35997
X-Complaints-To abuse@xs4all.nl
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!porbandar.httrack.net!news.httrack.net!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:61588

Show key headers only | View raw


On Thu, Dec 12, 2013 at 2:42 AM, bob gailer <bgailer@gmail.com> wrote:
> It also ensures that the defining all the classes and functions happens
> before referencing them (less "bookkeeping" for me).
>
> These two allow me to write the main program first, and follow it with all
> the global stuff.

I prefer define-before-use for readability, even if it doesn't matter
to the language. It means that locating the source of something can be
found by going upward (or starting at the top and going down - first
hit should be the definition), and helps keep things organized.
Obviously it's not always possible (mutual recursion, for instance),
but it's a general rule of thumb that I like to maintain.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Is there any advantage to using a main() in python scripts? JL <lightaiyee@gmail.com> - 2013-12-11 01:55 -0800
  Re: Is there any advantage to using a main() in python scripts? Ben Finney <ben+python@benfinney.id.au> - 2013-12-11 21:26 +1100
  Re: Is there any advantage to using a main() in python scripts? Chris Angelico <rosuav@gmail.com> - 2013-12-11 21:41 +1100
  Re: Is there any advantage to using a main() in python scripts? marduk@letterboxes.org - 2013-12-11 07:57 -0500
    Re: Is there any advantage to using a main() in python scripts? Roy Smith <roy@panix.com> - 2013-12-11 09:20 -0500
  Re: Is there any advantage to using a main() in python scripts? Roy Smith <roy@panix.com> - 2013-12-11 09:17 -0500
    Re: Is there any advantage to using a main() in python scripts? rusi <rustompmody@gmail.com> - 2013-12-11 06:24 -0800
  Re: Is there any advantage to using a main() in python scripts? bob gailer <bgailer@gmail.com> - 2013-12-11 10:42 -0500
  Re: Is there any advantage to using a main() in python scripts? Chris Angelico <rosuav@gmail.com> - 2013-12-12 02:49 +1100
  Re: Is there any advantage to using a main() in python scripts? Terry Reedy <tjreedy@udel.edu> - 2013-12-11 16:22 -0500

csiph-web