stdin, stdout, stderr
To get input from the user on stdin:
= input("Today's comment?: ")
s # `s` won't have a newline at the end.
Printing to stdout:
print('hey') # With newline.
print('hey', end='') # No newline.
print('a', 'b', 'c', sep=':') # Prints "a:b:c".
print('bye', flush=True) # Flush the stream.
Print to stderr:
import sys
print('hi', file=sys.stderr)
See also help(print)
.
Note that you can write backspaces to stdout to overwrite what’s there:
import sys
= sys.stdout.write, sys.stdout.flush
write, flush = 'hello'
s
write(s)
flush()'\x08' * len(s))
write(
flush()'j') # shows: jello write(
and
for c in itertools.cycle('|/-\\'):
write(c)
flush()0.1)
time.sleep('\x08') write(