newline controls how universal newlines mode works (it only applies to text mode). It can be
None
,''
,' '
,' '
, and' '
. It works as follows:[...]
- When writing output to the stream, if newline is
None
, any' '
characters written are translated to the system default line separator,os.linesep
. If newline is''
or' '
, no translation takes place. If newline is any of the other legal values, any' '
characters written are translated to the given string.
open(..., 'w', newline='')
当newline='
',read,write数据中的
都不会转化。