1. If you need better control of the output, and print does not meet the requirements, Sys.stdout,sys.stdin,sys.stderr is what you need.
2.sys.stdout and Print:
When you call print in Python, the sys.stdout.write (obj+ ' \ n ') is actually called
Print prints the required content to the console, and then appends a line break
The following two lines of code are equivalent:
Sys.stdout.write ('hello'\ n')print( ' Hello ')
3.sys.stdin and input
Sys.stdin.readline () will get all the standard input, including the ' \ n ' at the end, so the length is calculated with Len ' \ n ', but the result returned by input () does not include the end of the line feed ' \ n '.
Therefore, if you use Sys.stdin.readline () to get input, do not forget to remove the end of the line break, you can use the strip () function (Sys.stdin.readline (). strip (' \ n ') ) or Sys.stdin.readline () [:-1] These two methods remove line breaks.
4. Redirecting from console to file
The original sys.stdout points to the console, and if the object reference to the file is assigned to Sys.stdout, then print calls the Write method of the file object.
Python in Sys.stdout, Sys.stdin