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


Groups > comp.lang.python > #90487

Re: Python file structure

References <f25aa9d4-4025-457d-8072-5327c98db1bd@googlegroups.com> <CAPTjJmrtLoCGOAr+F1Q7zgzv3hUhvrVA3ADdaLe9mP9YSShi6Q@mail.gmail.com> <CALwzid=tsm9c6DWyQ+g72+uG_KM+eDQ2Be3Pgj5gj6sorhNGHw@mail.gmail.com>
Date 2015-05-13 06:07 +1000
Subject Re: Python file structure
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.413.1431461254.12865.python-list@python.org> (permalink)

Show all headers | View raw


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)

ChrisA

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