printWriting to Standard Output (stdout) using print is simple:
print( "Hello Standard Output!" )
But if you want to write to Standard Error (stderr), you'll have to import the sys library:
1 2 3 | import sys print( "Hello Standard Error!", file=sys.stderr ) |
writeYou can also write to stdout or stderr using the sys.stdout and sys.stderr file objects:
1 2 3 4 | import sys sys.stdout.write( "Hello Standard Output!\n" ) sys.stderr.write( "Hello Standard Error!\n" ) |
Whereas print automatically adds a newline character \n at the end, with sys.stdout.write and sys.stderr.write, you need to explicitly add it.