I have an input file which looks like
===========================
__A= 2.3
__b= 3.26
===========================
__ctx= 4.2
===========================
__itermax= 100
__errmax= 1e-07
Using this inputfile a collection of outputs within a different code( not implemented in python) has been generated. I am now trying to write some Python scripts to read this input file as well as other generated outputs to perform postproccessing analysis. I thus would like to extract the value of each parameter(A, b, ctx, ...) by a python script. Please note that this input file is distinct from the setting file discussed here as I can not perform any modification on the structure of the input file.
I have tried
import sys
try:
directory_name=sys.argv[1]
print(directory_name)
except:
print('Please pass directory_name')
input_file = directory_name +"input.txt"
with open(input_file) as fin:
for line in fin:
exec(line)
The error that I am encountering after running the code is
File "code.py", line 14, in <module>
exec(line)
File "<string>", line 1
===========================
^
SyntaxError: invalid syntax
Any suggestion on improving this code, or with a different outputting method (e.g. as a dictionary), to obtain the values of the parameters is helpful.