update
This commit is contained in:
		
							
								
								
									
										14
									
								
								2025.08.26_data_file_format/CSV_example.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								2025.08.26_data_file_format/CSV_example.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| import csv | ||||
|  | ||||
| # 写入 CSV | ||||
| with open('data.csv', 'w', newline='', encoding='utf-8') as f: | ||||
|     writer = csv.writer(f) | ||||
|     writer.writerow(['Name', 'year', 'value']) # 写入表头 | ||||
|     writer.writerow(['Guan', 1993, 1]) | ||||
|     writer.writerow(['G123', 2025, 0]) | ||||
|  | ||||
| # 读取 CSV | ||||
| with open('data.csv', 'r', encoding='utf-8') as f: | ||||
|     reader = csv.reader(f) | ||||
|     for row in reader: | ||||
|         print(row) # 每行是一个列表 | ||||
		Reference in New Issue
	
	Block a user