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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • scrapy学习笔记(有示例版) 我的博客 scrapy学习笔记1.使用scrapy1.1创建工程1.2创建爬虫模...
    陈思煜阅读 12,760评论 4 46
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,811评论 25 708
  • 自去年开始我也加入了朝九晚五的大军,周一至周五每天早上准时拎着包去挤电车。成了社会人士自然不能再像学生时代那么马虎...
    布酱阅读 839评论 4 2
  • 我喜欢旅行,或者说,更喜欢旅途。我喜欢在路途上的感觉,有目的地,心就有要去的地方。有向往的方向,心就是安定的。
    慌张girl阅读 231评论 0 0
  • 不怕千山万水的阻隔 不管路途多么遥远 大包小包的行李 装满沉甸甸的思念 怎能不惦记那小小的村落 和袅袅升起的炊烟 ...
    偶尔吃酒阅读 99评论 0 3