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


Groups > comp.lang.python > #90576

Re: Python file structure

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'args': 0.07; 'parser': 0.07; 'subject:file': 0.07; 'variables': 0.07; '"__main__":': 0.09; '__name__': 0.09; 'args)': 0.09; 'main()': 0.09; 'parsing': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '*only*': 0.16; '-tkc': 0.16; 'command-line': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'main():': 0.16; 'received:174.136': 0.16; 'script,': 0.16; 'sense,': 0.16; 'skip:[ 30': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; 'cc:addr:python.org': 0.22; 'looks': 0.24; 'environment': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'skip:_ 20': 0.27; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'specifically': 0.29; 'chris': 0.29; 'am,': 0.29; 'usually': 0.31; '13,': 0.31; 'invoke': 0.31; 'relies': 0.31; 'skip:d 20': 0.34; 'something': 0.35; 'but': 0.35; 'entry': 0.36; 'charset:us-ascii': 0.36; 'received:10': 0.37; 'being': 0.38; 'sometimes': 0.38; 'mine': 0.38; 'called': 0.40; 'ian': 0.60; 'tell': 0.60; 'real': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; '2015': 0.84
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-MC-Relay Neutral
X-MailChannels-SenderId wwwh|x-authuser|tim@thechases.com
X-MailChannels-Auth-Id wwwh
X-MC-Loop-Signature 1431542024010:3034590601
X-MC-Ingress-Time 1431542024010
Date Wed, 13 May 2015 13:34:22 -0500
From Tim Chase <python.list@tim.thechases.com>
To Chris Angelico <rosuav@gmail.com>
Cc Python <python-list@python.org>
Subject Re: Python file structure
In-Reply-To <CAPTjJmpDfdYZ1LXeHbHNTuv_L4vaNZXnz-yOffjc1sM8tAd1Uw@mail.gmail.com>
References <f25aa9d4-4025-457d-8072-5327c98db1bd@googlegroups.com> <CAPTjJmrtLoCGOAr+F1Q7zgzv3hUhvrVA3ADdaLe9mP9YSShi6Q@mail.gmail.com> <CALwzid=tsm9c6DWyQ+g72+uG_KM+eDQ2Be3Pgj5gj6sorhNGHw@mail.gmail.com> <CAPTjJmpDfdYZ1LXeHbHNTuv_L4vaNZXnz-yOffjc1sM8tAd1Uw@mail.gmail.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AuthUser tim@thechases.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.456.1431544287.12865.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431544287 news.xs4all.nl 2833 [2001:888:2000:d::a6]:51867
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90576

Show key headers only | View raw


On 2015-05-13 06:07, Chris Angelico wrote:
> On Wed, May 13, 2015 at 5:54 AM, Ian Kelly <ian.g.kelly@gmail.com>
> wrote:
> > Also, I like to put command-line parsing inside the main function
> > and make that its *only* responsibility. The main function then
> > calls the real entry point of my script, which will be something
> > more specifically named. This also has the advantage that if some
> > other module needs to invoke my script, all it has to do is call
> > the entry point function which will be named something more
> > suitable than "main".
> 
> That often makes sense, but sometimes doesn't. When it doesn't, you
> can usually tell because your main function looks something like
> this:
> 
> def main():
>     do_real_work(*sys.argv)
> if __name__=="__main__": main()
> 
> A one-line function that's called from one place? In-line it.
> 
> if __name__ == "__main__":
>     do_real_work(*sys.argv)

Usually mine look something like

  def do_real_work(options, args):
    ...
  def main():
    parser = [optparse,argparse,docopt]....
    options, args = parser.parse_args()
    do_real_work(options, args)
  if __name__ == "__main__":
    main()

since my real-work function usually relies on configuration
(sometimes this also includes a config-file or environment variables
being munged into some "options" data structure).

-tkc



  

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


Thread

Python file structure zljubisicmob@gmail.com - 2015-05-12 12:13 -0700
  Re: Python file structure Chris Angelico <rosuav@gmail.com> - 2015-05-13 05:29 +1000
  Re: Python file structure Ned Batchelder <ned@nedbatchelder.com> - 2015-05-12 12:49 -0700
    Re: Python file structure zljubisicmob@gmail.com - 2015-05-12 12:58 -0700
      Re: Python file structure Dave Angel <davea@davea.name> - 2015-05-12 16:43 -0400
    Re: Python file structure Chris Angelico <rosuav@gmail.com> - 2015-05-13 06:02 +1000
    Re: Python file structure Terry Reedy <tjreedy@udel.edu> - 2015-05-12 17:34 -0400
  Re: Python file structure Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-12 13:54 -0600
  Re: Python file structure Chris Angelico <rosuav@gmail.com> - 2015-05-13 06:07 +1000
  Re: Python file structure Tim Chase <python.list@tim.thechases.com> - 2015-05-13 13:34 -0500
  Re: Python file structure Chris Angelico <rosuav@gmail.com> - 2015-05-14 12:03 +1000

csiph-web