常见文件格数数据处理
with open('example.txt', 'w') as file: file.write('Hello, world!')with open('example.txt', 'r') as file: content = file.read() print(content)
import csv data = [['Name', 'Age'], ['Alice', '25'], ['Bob', '30']] with open('example.csv', 'w', newline='') as file: writer = csv.writer(file) writer.writerows(data)import csv with open('example.csv', 'r') as file: reader = csv.reader(file) for row in reader: print(row)
Last updated