Why truncate when we open a file in 'w' mode in python

前端 未结 8 2120
再見小時候
再見小時候 2020-12-13 05:40

I am going through Zed Shaw\'s Python Book. I am currently working on the opening and reading files chapters. I am wondering why we need to do a truncate, when we are alread

8条回答
  •  鱼传尺愫
    2020-12-13 06:33

    It's redundant since, as you noticed, opening in write mode will overwrite the file. More information at Input and Output section of Python documentation.

提交回复
热议问题