文本读写模式

Character Meaning

  • 'r' open for reading (default)
  • 'w' open for writing, truncating the file first
  • 'x' open for exclusive creation, failing if the file already exists
  • 'a' open for writing, appending to the end of the file if it exists
  • 'b' binary mode
  • 't' text mode (default)
  • '+' open a disk file for updating (reading and writing)
  • 'U' universal newlines mode (deprecated)

Truncate---删除。

不删除时的更新写入,还可以指定写入时的位置---开头还是结尾。

可以认为:sep默认模式是空格, end的默认模式是

原文地址:https://www.cnblogs.com/Henry-ZHAO/p/13671594.html