This question already has answers here:
Open files in 'rt' and 'wt' modes
(4个答案)
4年前关闭。
我对一段时间前写的一些代码感到困惑(是的,没有注释!),这与
在文本模式下(默认设置,或者
参数),文件内容以
已先使用平台相关的编码或使用
指定的编码(如果给出)。
(4个答案)
4年前关闭。
我对一段时间前写的一些代码感到困惑(是的,没有注释!),这与
"at"
中的with open
标志有关。是否存在它是因为我在上面找不到任何东西,如果不是,则是python(我使用3.4),只是忽略了“ t”部分。with open(cumulative_file ,'at') as c:
c_csv = csv.writer(c)
c_csv.writerows(hv_today)
最佳答案
是的,这是有效的。检查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'
中包含mode
参数),文件内容以
str
的形式返回,以字节为单位已先使用平台相关的编码或使用
指定的编码(如果给出)。