Re: How to exit program with custom code and custom message?

2023-03-13 Thread Chris Angelico
On Tue, 14 Mar 2023 at 15:28, Thomas Passin wrote: > > On 3/13/2023 10:34 PM, scruel tao wrote: > > Interesting, `raise SystemExit` seems to have the same behavior as > > `sys.exit`: > > > > ```shell > > python -c "raise SystemExit(100)" > > echo $? > > <<< 100 > > > > python -c " import sys;

Re: How to exit program with custom code and custom message?

2023-03-13 Thread Thomas Passin
On 3/13/2023 10:34 PM, scruel tao wrote: Interesting, `raise SystemExit` seems to have the same behavior as `sys.exit`: ```shell python -c "raise SystemExit(100)" echo $? <<< 100 python -c " import sys; sys.exit(100)" echo $? <<< 100 OTOH, you don't want to get too tricky: (on Windows,

Re: How to exit program with custom code and custom message?

2023-03-13 Thread Thomas Passin
On 3/13/2023 11:50 PM, MRAB wrote: On 2023-03-14 03:29, Thomas Passin wrote: On 3/13/2023 10:34 PM, scruel tao wrote: Lars: I totally understand your reasoning here, but in some way it follows the unix philosophy: Do only one thing, but do that good. I understand, python is not strongly

Re: How to exit program with custom code and custom message?

2023-03-13 Thread MRAB
On 2023-03-14 03:29, Thomas Passin wrote: On 3/13/2023 10:34 PM, scruel tao wrote: Lars: I totally understand your reasoning here, but in some way it follows the unix philosophy: Do only one thing, but do that good. I understand, python is not strongly typed, so `sys.exit` will be able to

Re: How to exit program with custom code and custom message?

2023-03-13 Thread Thomas Passin
On 3/13/2023 10:34 PM, scruel tao wrote: Lars: I totally understand your reasoning here, but in some way it follows the unix philosophy: Do only one thing, but do that good. I understand, python is not strongly typed, so `sys.exit` will be able to accept any types parameters rather than just

Re: How to exit program with custom code and custom message?

2023-03-13 Thread scruel tao
Lars: > I totally understand your reasoning here, but in some way it follows the unix > philosophy: Do only one thing, but do that good. I understand, python is not strongly typed, so `sys.exit` will be able to accept any types parameters rather than just integer. In order to handle such

Re: 转发: How to exit program with custom code and custom message?

2023-03-13 Thread Cameron Simpson
On 13Mar2023 10:18, scruel tao wrote: Chris: but for anything more complicated, just print and then exit. It's worth noting, by the way, that sys.exit("error message") will print that to STDERR, not to STDOUT, which mean that the equivalent is: Yes, I know, but don’t you think if `sys.exit`

Re: 转发: How to exit program with custom code and custom message?

2023-03-13 Thread Lars Liedtke
I totally understand your reasoning here, but in some way it follows the unix philosophy: Do only one thing, but do that good. And exiting is something different from printing to STDOUT or STDERR. Yes sometimes you want to print something before exiting. But then you should do that explicitly

转发: How to exit program with custom code and custom message?

2023-03-13 Thread scruel tao
Chris: > It doesn't actually take a list of arguments; the square brackets indicate that arg is optional here. Oh, I see, it seems that I mistunderstood the document. > but for anything more complicated, just print and then exit. > It's worth noting, by the way, that sys.exit("error message")

Re: How to exit program with custom code and custom message?

2023-03-13 Thread Chris Angelico
On Mon, 13 Mar 2023 at 20:00, scruel tao wrote: > > Currently, I use `sys.exit([arg])` for exiting program and it works fine. > As described in the document: > > If another type of object is passed, None is equivalent to passing zero, > > and any other object is printed to stderr and results in

How to exit program with custom code and custom message?

2023-03-13 Thread scruel tao
Currently, I use `sys.exit([arg])` for exiting program and it works fine. As described in the document: > If another type of object is passed, None is equivalent to passing zero, and > any other object is printed to stderr and results in an exit code of 1. However, if I want to exit the program