python 打开文件方式

xiaoxiao2021-02-28  13

========= =============================================================== Character Meaning --------- --------------------------------------------------------------- 'r' open for reading (default) 'w' open for writing, truncating the file first 'x' create a new file and open it for writing '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 newline mode (deprecated) ========= =============================================================== import csv# 使用数字和字符串的数字都可以datas = [['name', 'age'], ['Bob', 14], ['Tom', 23], ['Jerry', '18']]with open('example.csv', 'w', newline='') as f: writer = csv.writer(f) for row in datas: writer.writerow(row)
转载请注明原文地址: https://www.6miu.com/read-1750265.html

最新回复(0)