Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90481
| References | <f25aa9d4-4025-457d-8072-5327c98db1bd@googlegroups.com> |
|---|---|
| Date | 2015-05-13 05:29 +1000 |
| Subject | Re: Python file structure |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.410.1431458997.12865.python-list@python.org> (permalink) |
On Wed, May 13, 2015 at 5:13 AM, <zljubisicmob@gmail.com> wrote: > import... > > A = configparser.get(...) > B = configparser.get(...) > > Command line parameters parsing [they can change variable A or B] > > Def usage() > Print how to use script parameters > > def main(): > ... > > if __name__ == "__main__": > main() > > If I find an error in command line parameters section I cannot call function usage() because it is not defined yet. > > I have few options here: > 1. Put definition of usage function before command line parameters parsing section I'd do this, unless there's a good reason not to. A simple usage function probably doesn't have many dependencies, so it can logically go high in the code. As a general rule, I like to organize code such that things are defined higher up than they're used; it's not strictly necessary (if they're used inside functions, the requirement is only that they be defined before the function's called), but it helps with clarity. That generally means that "def usage():" wants to go up above any place where "usage()" occurs, but below the definitions of any functions that usage() itself calls, and below the first assignments to any global names it uses. It's not always possible, but when it is, it tends to produce an easy-to-navigate source file. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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