sys.stderr.write and sys.exit

G

GinTon

Is the same use _sys.stderr.write('error message'); sys.exit(1)_ than
_sys.exit('error message')_ ?

Note: help(sys.exit)
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is numeric, 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).
 
B

Ben Finney

GinTon said:
Is the same use _sys.stderr.write('error message'); sys.exit(1)_
than _sys.exit('error message')_ ?

(Note: The underscore '_' is a valid character in Python code, so I
was quite confused by what you wrote and had to read it several times
to see that you were intending the underscores not to be part of the
code. Better to show a line of code on its own line in your message.)

Code that wants to catch SystemExit will get a different exception
object in each case::
... sys.stderr.write('error message')
... sys.exit(1)
... except SystemExit, e:
... print "stderr contains:", sys.stderr.getvalue()
... print "e.code is:", e.code
...
stderr contains: error message
e.code is: 1
... sys.exit('error message')
... except SystemExit, e:
... print "stderr contains:", sys.stderr.getvalue()
... print "e.code is:", e.code
...
stderr contains: error message
e.code is: error message

I quite often catch SystemExit in unit tests, or other code that is
inspecting a program module.
 
D

Dennis Lee Bieber

(Note: The underscore '_' is a valid character in Python code, so I
was quite confused by what you wrote and had to read it several times
to see that you were intending the underscores not to be part of the
code. Better to show a line of code on its own line in your message.)
Old "rich text" email format effectors... *word* => bolded, /word/
=> italic, _word_ => underscored. Some email clients could actually
parse those for rendering purposes, but it wasn't required to render
such on input. And given the commonality of email and netnews content,
probably some news clients did too (I think kmail understand the syntax
on display)
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
B

Ben Finney

Dennis Lee Bieber said:
Old "rich text" email format effectors... *word* => bolded, /word/
=> italic, _word_ => underscored.

Yes, I use those (or similar) myself, but only in natural language
where the context makes it clear that the punctuation characters are
not intended to be part of the content. When showing program code,
it's a poor choice to use punctuation characters for such markup,
since it's not clear which ones are part of the code.
 
D

Dennis Lee Bieber

Yes, I use those (or similar) myself, but only in natural language
where the context makes it clear that the punctuation characters are
not intended to be part of the content. When showing program code,
it's a poor choice to use punctuation characters for such markup,
since it's not clear which ones are part of the code.

Aye -- I didn't go back to see what client was being used by the
poster; perhaps it was one that, somehow, parsed those characters even
when editing the text and displayed in those forms... hiding the fact
that the plain text could be misleading <G>

Of course, I tend to giggle some at the complaints about how 1 and
"ell" can be confused -- the font on my client makes those quite
distinct... but "EYE" and "ell" (I, l) are visually identical! (at 400%,
even)
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top