Open files in 'rt' and 'wt' modes

后端 未结 4 1567
故里飘歌
故里飘歌 2020-11-29 19:54

Several times here on SO I\'ve seen people using rt and wt modes for reading and writing files.

For example:

with open(\'in         


        
4条回答
  •  孤街浪徒
    2020-11-29 20:45

    The 'r' is for reading, 'w' for writing and 'a' is for appending.

    The 't' represents text mode as apposed to binary mode.

    Several times here on SO I've seen people using rt and wt modes for reading and writing files.

    Edit: Are you sure you saw rt and not rb?

    These functions generally wrap the fopen function which is described here:

    http://www.cplusplus.com/reference/cstdio/fopen/

    As you can see it mentions the use of b to open the file in binary mode.

    The document link you provided also makes reference to this b mode:

    Appending 'b' is useful even on systems that don’t treat binary and text files differently, where it serves as documentation.

提交回复
热议问题