Questions tagged «zen-of-python»

15
如何在Python中打印到stderr?
有几种写stderr的方法: # 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) 这似乎与zen的Python#13 †相矛盾,所以这里有什么区别,一种方法或另一种方法有什么优点或缺点?应该使用哪种方式? † 应该有一种(最好只有一种)明显的方式来做到这一点。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.