I am trying to replace some values inside a multiline string. To do that, I do the following steps:
- I define a raw string in which the values that I want to customize later are enclosed by curly brackets.
- I create a dictionary with my customization options.
- I look over the keys of the dictionary and replace them by their corresponding value using replace().
Altough it seems to make sense (for me) for some reason it is not working. A MWE is attached below:
customString = r'''%- Hello!
%- Axis limits
xmin= {xmin}, xmax= {xmax},
ymin= {ymin}, ymax= {ymax},
%- Axis labels
xlabel={xlabel},
ylabel={ylabel},
'''
tikzOptions = {'xmin': 0,
'xmax': 7.5,
'ymin': -100,
'ymax': -40,
'xlabel': '{Time (ns)}',
'ylabel': '{Amplitude (dB)}',}
for key in tikzOptions.keys():
searchKey = '{' + key + '}' # Defined key on dictionary tikzOptions
value = str(tikzOptions[key]) # Desire value for plotting
customString.replace(searchKey,value)
print(customString)
The result of this code should be:
%- Hello!
%- Axis limits
xmin= 0, xmax= 7.5,
ymin= -100, ymax= -40,
%- Axis labels
xlabel=Time(ns),
ylabel=Amplitude (dB),
But the output that I get is exactly the same string that I defined, customString. Could you help me?