Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100182

Re: storing test logs under /var/log/

From Cameron Simpson <cs@zip.com.au>
Newsgroups comp.lang.python
Subject Re: storing test logs under /var/log/
Date 2015-12-09 12:51 +1100
Message-ID <mailman.82.1449627771.12405.python-list@python.org> (permalink)
References <n46i6m$4lv$1@ger.gmane.org>

Show all headers | View raw


On 08Dec2015 13:24, Peter Otten <__peter__@web.de> wrote:
>Ganesh Pal wrote:
>[Cameron Simpson:]
>>> Finally. sys.exit accepts an integer, not a string.
>
>> Most of code  uses sys.exit("some error message")   ,  I did notice
>> that the error message is not displayed by sys .exit("some error
>> message") ,  do  u mean that using string is not advisable with
>> sys.exit ?
>
>Cameron is wrong (he's probably coming from the C side of things).

Correct on both counts.

>You can invoke sys.exit() with arbitrary objects:
[...]
>    Exit the interpreter by raising SystemExit(status).
>    If the status is omitted or None, it defaults to zero (i.e., success).
>    If the status is an integer, it will be used as the system exit status.
>    If it is another kind of object, it will be printed and the system
>    exit status will be one (i.e., failure).

I Did Not Know That!

It says "printed". To stderr or stdout? If it isn't stderr, I think I will 
avoid this anyway.

>> How to I display error messages with sys.exit then ?
>Wrong question; if you want to use sys.exit() in a way similar to C display
>the error message first and invoke sys.exit() afterwards with a numerical
>argument.

Indeed. My general habit is that fatal errors (when the code decides that they 
are fatal) print or log an error message and set a suitable failure flag. Which 
is then caught later somewhere suitable.

Cheers,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: storing test logs under /var/log/ Cameron Simpson <cs@zip.com.au> - 2015-12-09 12:51 +1100

csiph-web