今天看穿山甲的那本爬蟲(chóng)書(shū),在創(chuàng)建CSV文件那一章節(jié)看到這樣的代碼
csvFile = open("files/editors.csv", 'wt', newline='', encoding='utf-8')
突然對(duì)'wt'感到模式颇象,開(kāi)始以為是csv的特殊用法伍伤,后來(lái)經(jīng)過(guò)搜索在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)
簡(jiǎn)單一句話(huà)概括就是:t表示text,這個(gè)是默認(rèn)的,所以wt=w,rt=r