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


Groups > comp.lang.python > #90600

Re: Python file structure

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.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; 'deprecated': 0.09; 'main()': 0.09; 'means,': 0.09; 'url:github': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'bit.': 0.16; 'dislike': 0.16; 'elsewhere,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'main().': 0.16; 'main():': 0.16; 'skip:[ 30': 0.16; 'sure.': 0.16; 'url:py': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'config': 0.24; 'environment': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'am,': 0.29; 'tim': 0.29; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'chase': 0.31; 'end,': 0.31; 'relies': 0.31; 'trivial': 0.31; 'themselves': 0.32; 'becomes': 0.33; 'skip:d 20': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'done': 0.36; 'project': 0.37; 'being': 0.38; 'mine': 0.38; 'rather': 0.38; 'though,': 0.39; 'new': 0.61; 'real': 0.63; '2015': 0.84; 'duplication': 0.84; 'url:master': 0.84; 'favour': 0.91; 'to:none': 0.92
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=rrNyH8XeBR+OOtEtrE/r2R/mAZIVGgKUecwVFczJSBU=; b=pek3CfO7ku0b8r/n87v7qKUsarL97G4CC+lXDhZgb93vhvIwjhuYI9SKOk1aemXoYA YbCcD1h2UA4emtgBxi9gapUg38Lb9fuq8Ksh5AnnkP5bsBalqRa+nu7RGf4AHXhybwnx Ew/pLzejGmXVtFAY/oMdg3A+M6n/5xkHDHSSeP1zR1enZ3HhKPbFFUo54hpn4NaI5C3L AQhp8d6AQiDrV6L+9ZiMzWtUoO5iS0krxv4HqsvbAz8NBroJgexco7qYXkOg9Y4Qd8hf iLW+QtMNlvjGKXv4ikCD0TEXjAZsrRw7LruQba83b1U7MMykRoWPJVPyJL3vuA9Z6C1J H4ew==
MIME-Version 1.0
X-Received by 10.107.160.141 with SMTP id j135mr2266297ioe.43.1431569029999; Wed, 13 May 2015 19:03:49 -0700 (PDT)
In-Reply-To <20150513133422.78617956@bigbox.christie.dr>
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> <20150513133422.78617956@bigbox.christie.dr>
Date Thu, 14 May 2015 12:03:49 +1000
Subject Re: Python file structure
From Chris Angelico <rosuav@gmail.com>
Cc Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.473.1431569039.12865.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431569039 news.xs4all.nl 2848 [2001:888:2000:d::a6]:33926
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90600

Show key headers only | View raw


On Thu, May 14, 2015 at 4:34 AM, Tim Chase
<python.list@tim.thechases.com> wrote:
> 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).
>

Sure. I rather dislike the whole duplication that that entails,
though, so I try to have the functions themselves do their own
argparse config. To that end, I put together a new project on PyPI,
but have now deprecated it in favour of Clize; the upshot is that my
main function becomes trivial again:

https://github.com/Rosuav/LetMeKnow/blob/master/letmeknow.py

@command
def await(...):
    """argparse config comes from here"""

if __name__ == "__main__":
    clize.run(commands)

So it comes and goes a bit. If there's real content in your main(),
then by all means, separate it out from do_real_work; but if the work
is all done elsewhere, not much point with main().

ChrisA

Back to comp.lang.python | Previous | NextPrevious 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