Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-16 Thread Steven D'Aprano
On Sun, 17 Apr 2016 02:09 am, Dennis Lee Bieber wrote: > VMS had a whole slew of "no error" status values (essentially all > positive odd integers were "success", but different values carried > additional information. 1 = success 3 = success against all odds 5 = success but at great cost 7 = su

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-16 Thread Ben Finney
Dennis Lee Bieber writes: > On Sat, 16 Apr 2016 16:56:10 +1000, Ben Finney > declaimed the following: > > >It seems strange that even the constant for “no error” exit status > >should be defined only for Unix :-/ > > VMS had a whole slew of "no error" status values That's fine; those valu

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-16 Thread Chris Angelico
On Sat, Apr 16, 2016 at 4:56 PM, Ben Finney wrote: > Stephen Hansen writes: > >> > * You can use named constants from ‘os’ for the purpose of specifying >> > exit status numbers. >> >> Only on *nix. > > Hmm, I didn't see that. It seems strange that even the constant for “no > error” exit status

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-16 Thread Ben Finney
Stephen Hansen writes: > > * You can use named constants from ‘os’ for the purpose of specifying > > exit status numbers. > > Only on *nix. Hmm, I didn't see that. It seems strange that even the constant for “no error” exit status should be defined only for Unix :-/ -- \ “Geeks like

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-15 Thread Stephen Hansen
> * You can use named constants from ‘os’ for the purpose of specifying > exit status numbers. Only on *nix. Even then it varies from platform to platform which constants you can use. I'd prefer to document the return status and use numbers/my own constants directly, that way supporting any p

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-15 Thread Ben Finney
c...@zip.com.au writes: > My preferred pattern is like this: > > def main(argv): >try: > ... >except Exception as e: > logging.exception(e) > return 1 > > if __name__ == '__main__': >sys.exit(main(sys.argv)) > > Notice that main() is back to being a normal function wit

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-15 Thread cs
On 12Apr2016 18:20, Ganesh Pal wrote: I m on python 2.7 and Linux , I have a simple code need suggestion if I I could replace sys.exit(1) with raise SystemExit . ==Actual code== def main(): try: create_logdir() create_dataset() unittest.main() except Exception as

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Ben Finney
"Martin A. Brown" writes: > The only change from what Ben suggests is that, once I found os.EX_OK, > I just kept on using it, instead of difining my own EXIT_SUCCESS in > every program. Ah, thank you! I was unaware of the exit-status constants in ‘os’:: The following exit codes are defined

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Martin A. Brown
Hello all, Apologies for this post which is fundamentally, a 'me too' post, but I couldn't help but chime in here. >This is good practice, putting the mainline code into a ‘main’ >function, and keeping the ‘if __name__ == '__main__'’ block small >and obvious. > >What I prefer to do is to make

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Ben Finney
Ganesh Pal writes: > I m on python 2.7 and Linux , I have a simple code need suggestion if I > I could replace sys.exit(1) with raise SystemExit . No, but you can replace:: sys.exit(1) with:: raise SystemExit(1) As you know from reading the ‘sys.exit’ documentation https://docs.

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Random832
On Tue, Apr 12, 2016, at 10:12, Ganesh Pal wrote: > > > > > > No; raise SystemExit is equivalent to sys.exit(0); you would need raise > > SystemExit(1) to return 1. > > > > Thanks will replace SystemExit with SystemExit(1) . > > > > > Why do you want to do this, though? What do you think you ga

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Ganesh Pal
> > > No; raise SystemExit is equivalent to sys.exit(0); you would need raise > SystemExit(1) to return 1. > Thanks will replace SystemExit with SystemExit(1) . > Why do you want to do this, though? What do you think you gain from it? > Iam trying to have a single exit point for many function

Re: sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Random832
On Tue, Apr 12, 2016, at 08:50, Ganesh Pal wrote: > I m on python 2.7 and Linux , I have a simple code need suggestion if > I > I could replace sys.exit(1) with raise SystemExit . No; raise SystemExit is equivalent to sys.exit(0); you would need raise SystemExit(1) to return 1. Why do you wa

sys.exit(1) vs raise SystemExit vs raise

2016-04-12 Thread Ganesh Pal
I m on python 2.7 and Linux , I have a simple code need suggestion if I I could replace sys.exit(1) with raise SystemExit . ==Actual code== def main(): try: create_logdir() create_dataset() unittest.main() except Exception as e: logging.exception(e)