on-internet
← Community

How do I print to stderr in Python?

Stack Overflow ·

There are several ways to write to stderr: print >> sys.stderr, "spam" # Python 2 only. sys.stderr.write("spam\n") os.write(2, b"spam\n") from __future__ import print_function print("spam", file=sys.stderr) What are the differences between these methods? Which method should be preferred?

Comments

Sign in or sign up to comment and upvote.

No comments yet.