Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90494
| Date | 2015-05-12 16:43 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Python file structure |
| References | <f25aa9d4-4025-457d-8072-5327c98db1bd@googlegroups.com> <026e6357-917c-4d50-b70f-70903aa0e065@googlegroups.com> <05daad5f-b728-48ee-bf06-5e7374df936d@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.418.1431463424.12865.python-list@python.org> (permalink) |
On 05/12/2015 03:58 PM, zljubisicmob@gmail.com wrote: > On Tuesday, May 12, 2015 at 9:49:20 PM UTC+2, Ned Batchelder wrote: >> >> If you need to use globals, assign them inside a parse_arguments >> function that has a "global" statement in it. >> >> This advice is consistent with Chris' "define things before they >> are used." It does it by defining everything before anything is >> run. >> >> As a side note, if you are going to have code at the top-level of >> the file, then there's no point in the "if __name__..." clause. >> That clause is designed to make a file both runnable and importable. >> But your top-level code makes the file very difficult to import. >> >> --Ned. > > It makes sense. The only drawback is that variables are global only "if you need to use globals". You can't have it both ways. If they're needed, it's because you feel they must be changeable elsewhere in the program. I try to avoid global variables, but make no such restraints on the use of global constants. So for example, the argument parsing logic could very well export something as global, but it'd be all uppercase and anyone changing it subsequently would get their hand slapped by the linter. > so they could be changed anywhere in the program. > I also agree that it is more python approach. > > Thanks to both of you. > -- DaveA
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