Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90600
| 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 | 2015-05-14 12:03 +1000 |
| Subject | Re: Python file structure |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.473.1431569039.12865.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Find similar | Unroll 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