In Python, you can use the print() function to print to stderr by passing the value file=sys.stderr as a keyword argument. For example:
This will print the string "This is an error message" to the standard error stream.
Alternatively, you can use the sys.stderr.write() method to write a string to the standard error stream:
This will have the same effect as the print() function above.
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.