【问题标题】:What does the "w" mean in open(filename, "w")? [duplicate]open(filename, "w") 中的 "w" 是什么意思? [复制]
【发布时间】:2015-03-26 12:15:21
【问题描述】:

我正在阅读“Learn Python The Hard way”的练习 16,我对 open(filename, "w") 感到困惑——"w" 是什么意思?

【问题讨论】:

    标签: python


    【解决方案1】:

    "w" 指定正在写入的文件。如您所见here"w" 是您写入文件时使用的模式。

    mode 最常用的值是 'r' 用于读取,'w' 用于写入(如果文件已存在则截断文件)...

    【讨论】:

      【解决方案2】:

      “W”表示您打开名为 filename 的文件是为了写入(因此“W”表示写入。)

      【讨论】:

        【解决方案3】:

        打开文件名的第二个参数表示您正在使用的模式(即只读、可写)。在这种情况下,它能够(写)写入文件。

        https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files

        【讨论】:

          【解决方案4】:

          w代表打开文件的写权限

          open(name[, mode[, buffering]])
          

          查看签名我们可以(通常)理解每个参数的作用 更多信息here

          【讨论】:

            猜你喜欢
            • 2015-01-05
            • 2017-08-14
            • 2010-11-19
            • 2023-03-31
            • 1970-01-01
            • 2013-04-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多