I am trying to write a file from a sample template file.
I need to replace ONLY $UPPERINTERFACE with interface.
This is the sample template.txt
localparam $UPPERINTERFACE_WDTH = 1;
localparam $UPPERINTERFACE_DPTH = 8;
localparam $UPPERINTERFACE_WTCHD = 2;
This is the code:
from string import Template
intf = "interface"
rdfh = open("template.txt", "r").readlines()
wrfh = open("myfile.txt", "w")
for line in rdfh:
s = Template(line)
s = s.substitute(UPPERINTERFACE=intf.upper())
wrfh.write(s)
rdfh.close()
wrfh.close()
Expected output:
localparam interface_WDTH = 1;
localparam interface_DPTH = 8;
localparam interface_WTCHD = 2;
As it is taking $UPPERINTERFACE_WDTH as a variable to be replaced, I am getting following error:
KeyError: 'UPPERINTERFACE_WDTH'
Is there any way I can replace only $UPPERINTERFACE with interface here?