Open files in 'rt' and 'wt'有什么区别?

今天看穿山甲的那本爬虫书,在创建CSV文件那一章节看到这样的代码

csvFile = open("files/editors.csv", 'wt', newline='', encoding='utf-8')

突然对’wt’感到模式,开始以为是csv的特殊用法,后来经过搜索在stackoverflow上查到以下信息:

    t refers to the text mode. There is no difference between r and rt or w and wt since text mode is the default.
    Documented [here](https://docs.python.org/3/library/functions.html#open):
    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)

简单一句话概括就是:t表示text,这个是默认的,所以wt=w,rt=r

    原文作者:everfight
    原文地址: https://www.jianshu.com/p/30b045cd3693
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞