zoukankan      html  css  js  c++  java
  • python open mode

    • 必须其一: r, w, a: read(默认), write, append

    • 可选: b, t, +, U: binary, text(默认), reading and writing, universal newlines mode

    • rt == r, wt == w, at == a

    • r+

      >>> with open('aa', 'r+') as f:
      ...     print(f.tell())
      ...
      0
      >>> with open('aa', 'r+') as f:
      ...     f.readline()
      ...     print(f.tell())
      ...
      '0
      '
      2
      
      • 读执行在前, 写执行在后: 添加到最后一行
      • 写执行在前: 写入并替换第一行内容
    • w+ == w

    • a+ == a

  • 相关阅读:
    Spock
    Spock
    Spock
    Spock
    Spock
    Spock
    Python3 与 Python2 的不同
    python 文件处理
    Django 数据迁移
    Python 特殊方法
  • 原文地址:https://www.cnblogs.com/edhg/p/12674529.html
Copyright © 2011-2022 走看看