import sys
sys.stdin
and sys.stdout
sys.stdin
and sys.stdout
sys.stdin
and sys.stdout
are useful when creating an interactive session. sys.stdin
is a file object and we can loop it through its iterator:
Status Bar
Build a status bar using sys.stdout.write
. The \r
moves the cursor to the beginning of the line:
input()
vs. sys.stdin.readline()
input()
vs. sys.stdin.readline()
input() | sys.stdin.readline() |
---|---|
The input takes input from the user but does not read escape character. | The readline() also takes input from the user but also reads the escape character. |
It has a prompt that represents the default value before the user input. | Readline has a parameter named size, Which is a non-negative number, it actually defines the bytes to be read. |
Reference
Last updated