Re: Python file structure

2015-05-13 Thread Chris Angelico
On Thu, May 14, 2015 at 4:34 AM, Tim Chase 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

Re: Python file structure

2015-05-13 Thread Tim Chase
On 2015-05-13 06:07, Chris Angelico wrote: > On Wed, May 13, 2015 at 5:54 AM, Ian Kelly > 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 some

Re: Python file structure

2015-05-12 Thread Terry Reedy
On 5/12/2015 3:49 PM, Ned Batchelder wrote: On Tuesday, May 12, 2015 at 3:13:32 PM UTC-4, zljubi...@gmail.com wrote: Hi, I have python file with the following structure: import... A = configparser.get(...) B = configparser.get(...) Command line parameters parsing [they can change variable A o

Re: Python file structure

2015-05-12 Thread Dave Angel
On 05/12/2015 03:58 PM, zljubisic...@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

Re: Python file structure

2015-05-12 Thread Chris Angelico
On Wed, May 13, 2015 at 5:54 AM, Ian Kelly 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 ad

Re: Python file structure

2015-05-12 Thread Chris Angelico
On Wed, May 13, 2015 at 5:49 AM, Ned Batchelder wrote: > I would put all of the code into a function some place. Don't have > anything at the top level of the file except imports, function (and > class) definitions, and an "if __name__." clause at the bottom. > > If you need to use globals, a

Re: Python file structure

2015-05-12 Thread zljubisicmob
On Tuesday, May 12, 2015 at 9:49:20 PM UTC+2, Ned Batchelder wrote: > On Tuesday, May 12, 2015 at 3:13:32 PM UTC-4, zljubi...@gmail.com wrote: > > Hi, I have python file with the following structure: > > > > import... > > > > A = configparser.get(...) > > B = configparser.get(...) > > > > Comma

Re: Python file structure

2015-05-12 Thread Ian Kelly
On Tue, May 12, 2015 at 1:29 PM, Chris Angelico wrote: > On Wed, May 13, 2015 at 5:13 AM, wrote: >> 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 b

Re: Python file structure

2015-05-12 Thread Ned Batchelder
On Tuesday, May 12, 2015 at 3:13:32 PM UTC-4, zljubi...@gmail.com wrote: > Hi, I have python file with the following structure: > > import... > > A = configparser.get(...) > B = configparser.get(...) > > Command line parameters parsing [they can change variable A or B] > > Def usage() >

Re: Python file structure

2015-05-12 Thread Chris Angelico
On Wed, May 13, 2015 at 5:13 AM, 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

Python file structure

2015-05-12 Thread zljubisicmob
Hi, I have python file with the following structure: 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__": m