Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson Newsgroups: comp.lang.python Subject: Re: storing test logs under /var/log/ Date: Wed, 9 Dec 2015 12:51:22 +1100 Lines: 38 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de q+zdp2eWSs2cuc0W/pBxPQZHhGqjcB8oNhtmfv3ldjnQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'string.': 0.04; 'defaults': 0.05; 'none,': 0.05; 'sys': 0.05; 'exit': 0.07; 'subject:test': 0.07; 'cc:addr:python-list': 0.09; 'integer,': 0.09; 'objects:': 0.09; 'stderr': 0.09; 'interpreter': 0.15; '(when': 0.16; 'afterwards': 0.16; 'fatal': 0.16; 'fatal)': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'status.': 0.16; 'subject:log': 0.16; 'subject:under': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.16; 'later': 0.16; 'string': 0.17; 'numerical': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cheers,': 0.22; 'cc:no real name:2**0': 0.22; 'errors': 0.23; 'somewhere': 0.24; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'error': 0.27; 'object,': 0.27; 'correct': 0.28; 'accepts': 0.29; 'invoke': 0.29; 'omitted': 0.29; 'print': 0.30; 'subject:/': 0.30; 'code': 0.30; '(i.e.,': 0.30; 'probably': 0.31; 'another': 0.32; 'says': 0.32; 'displayed': 0.33; 'raising': 0.33; 'that!': 0.33; 'similar': 0.33; "isn't": 0.35; 'subject:: ': 0.37; 'display': 0.37; 'charset :us-ascii': 0.37; 'wrong': 0.38; 'log': 0.38; 'mean': 0.38; 'suitable': 0.61; 'avoid': 0.61; 'side': 0.62; 'cameron': 0.66; 'received:61': 0.72; '>you': 0.84; 'flag.': 0.84; 'message")': 0.84; 'otten': 0.84; 'habit': 0.91 X-Authentication-Info: Submitted using ID cskk@bigpond.com X-Authority-Analysis: v=2.0 cv=JY8+XD2V c=1 sm=1 a=S5mshXgnUL+txs7PS9qVUg==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=wUQvQvOEmiQA:10 a=Vwki_maET9jmKbZacy0A:9 a=CjuIK1q_8ugA:10 a=S5mshXgnUL+txs7PS9qVUg==:117 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100182 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