How to output to stderr

anonymity
Release: 2020-10-21 11:13:42
Original
2610 people have browsed it

sys.stderr The purpose is to return error information

How to output to stderr

For example:

shutddown will prompt an error in red font.

>>> shutddown
Traceback (most recent call last):
  File "", line 1, in
    shutddown
NameError: name 'shutddown' is not defined
Copy after login

You can think about it, when we customize a function and then need to prompt the user for an error, but obviously it prints out in green font, then sys.stderr comes into play.

>>> import sys
>>> print 'closing...'
closing...
>>> print >> sys.stderr,'closing...'
closing...
>>> def test(x):
if x == 0: print >> sys.stderr,'Error--> x:can\'t is zero'
else:print x
>>> test('what\'s')
what's
>>> test(0)
Error--> x:can't is zero
>>>
Copy after login

or as follows:

>>> sys.stderr.write('sf')
sf
>>> print sys.stderr.write('sf')
sfNone
Copy after login

Related free learning recommendations: python video tutorial

The above is the detailed content of How to output to stderr. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:如何输出到stderr
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!