用于计算定时器初值
This commit is contained in:
23
other/csv2json.py
Normal file
23
other/csv2json.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#coding=utf-8
|
||||
import csv
|
||||
import json
|
||||
|
||||
# 文件路径
|
||||
file_path = 'note_data.txt'
|
||||
|
||||
# 读取文件并转换为 JSON
|
||||
notes_dict = {}
|
||||
with open(file_path, mode='r', encoding='utf-8') as file:
|
||||
reader = csv.DictReader(file, delimiter='\t')
|
||||
|
||||
for row in reader:
|
||||
note, frequency, wave_length = row['note'], row['frequency'], row['wave_length']
|
||||
notes_dict[note] = {'frequency': float(frequency), 'wave_length': float(wave_length)}
|
||||
|
||||
# 将数据转换为 JSON 并打印
|
||||
json_data = json.dumps(notes_dict, indent=4)
|
||||
print(json_data)
|
||||
|
||||
# 写入 JSON 文件
|
||||
with open('note_data.json', 'w', encoding='utf-8') as json_file:
|
||||
json_file.write(json_data)
|
||||
Reference in New Issue
Block a user