I am outputting a file, by populating it with values in certain locations. Any of the names inside the [] brackets are being populated with actual values. But since the values are different in length the format is mess up, how can I do this?
Thank you!
Input file
type xga_control_type is record
[NAME] : std_logic; -- [OFFSET] : [DESCRIPTOIN]
end record xga_control_type;
Python code
input=open("input.txt","r")
output=open("output.txt","w")
for line in input:
line=input.readlines()
if '[OFFSET]' in line:
line=line.replace('[OFFSET]',register[i]['offset'])
if '[NAME]' in line:
line=line.replace('[OFFSET]',register[i]['name'])
if '[DESCRIPTION]' in line:
line=line.replace('[DESCRIPTION]',register[i]['description'])
output.write(line)
Current output
type xga_control_type is record
reserved : std_logic; -- 31..27 :
force_all_fault_clear : std_logic; -- 26 : Rising edge forces all fault registers to clear
force_warning : std_logic; -- 25 : Forces AC2 to report a Master Warning
force_error : std_logic; -- 24 : Forces AC2 to report a Master Error
reserved : std_logic; -- 23..22 :
ref_delay_cnt : std_logic; -- 21..20 : Number of reference commands to delay output by. Counts in 4us increments
end record xga_control_type;
Desired output
type xga_control_type is record
reserved : std_logic; -- 31..27 :
force_all_fault_clear : std_logic; -- 26 : Rising edge forces all fault registers to clear
force_warning : std_logic; -- 25 : Forces AC2 to report a Master Warning
force_error : std_logic; -- 24 : Forces AC2 to report a Master Error
reserved : std_logic; -- 23..22 :
ref_delay_cnt : std_logic; -- 21..20 : Number of reference commands to delay output by. Counts in 4us increments
end record xga_control_type;