python 打开文件方式

========= ===============================================================
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)

猜你喜欢

转载自blog.csdn.net/njupt_yangj/article/details/80261738