0925 add usable yamls

This commit is contained in:
FelixChan
2025-09-25 15:41:00 +08:00
parent a20c1ed814
commit 5b8bfd70e3
95 changed files with 906 additions and 47 deletions

View File

@ -0,0 +1,20 @@
# 读取路径下所有的yaml文件批量替换指定的字符串
import os
import yaml
import glob
import re
# 指定要替换的字符串和新的字符串
old_string = 'NestedMusicTransformer'
new_string = 'AmadeusModel'
# 指定yaml文件所在的目录
directory = 'Amadeus/symbolic_yamls/nn_params'
# 遍历目录下的所有yaml文件
for filepath in glob.glob(os.path.join(directory, '*.yaml')):
with open(filepath, 'r', encoding='utf-8') as file:
content = file.read()
# 使用正则表达式替换指定的字符串
new_content = re.sub(r'\b' + re.escape(old_string) + r'\b', new_string, content)
# 将修改后的内容写回文件
with open(filepath, 'w', encoding='utf-8') as file:
file.write(new_content)
print(f'Processed file: {filepath}')