i'm setting some parameters in testing.yaml
a :
one :
file_name : 10/a_one 10.xlsx
index_col : 0
which i can read in python through the script below with no problem
with open('testing.yaml') as f:
data = ruamel.yaml.load(f, Loader=ruamel.yaml.Loader)
print(f"{data['a']['one']['file_name']}")
the output is 10/a_one 10.xlsx
. i will save a dataframe
from this input using pd.read_excel()
. however, if i want to include formattable strings which are changed from within python, i get an error. for example: say i want to be able to change the 10
in python, i edit testing.yaml
a :
one :
file_name : {month}/a_one {month}.xlsx
index_col : 0
and the script in python would then say
month = 10
with open('testing.yaml') as f:
data = ruamel.yaml.load(f, Loader=ruamel.yaml.Loader)
print(f"{data['a']['one']['file_name']}")
i expect the output to be 10/a_one 10.xlsx
again here, can i achieve this somehow? the reason i don't want to make all changes within in the YAML-file directly, is because that some formatting information (in this case month = 10
) is coming from another excel-file which is read within python.
question from:
https://stackoverflow.com/questions/65863178/read-curly-braces-yaml-to-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…