如何在Python中打印到stderr? - How to print to stderr in Python?

问题:

There are several ways to write to stderr: 有几种写stderr的方法: this

# Note: this first one does not work in Python 3
print >> sys.stderr, "spam"

sys.stderr.write("spam\n")

os.write(2, b"spam\n")

from __future__ import print_function
print("spam", file=sys.stderr)

That seems to contradict zen of Python #13 , so what's the difference here and are there any advantages or disadvantages to one way or the other? 这彷佛与zen的Python#13 相矛盾,因此这里有什么区别,一种方式或另外一种方式有什么优势或缺点? Which way should be used? 应该使用哪一种方式? spa

There should be one — and preferably only one — obvious way to do it. 应该有一种-最好只有一种-显而易见的方法。 .net


解决方案:

参考一: https://stackoom.com/question/NOEY/如何在Python中打印到stderr
参考二: https://oldbug.net/q/NOEY/How-to-print-to-stderr-in-Python
相关文章
相关标签/搜索