Aug-29-2018, 08:30 PM
You could simply use Python's format method
template = """\ TEMPOP /home/c.blanes/FlexAID2/FlexAID_Output PDBNAM /home/c.blanes/FlexAID2/Processed_files/receptor.inp.pdb INPLIG /home/c.blanes/FlexAID2/Processed_files/{ligand}.inp RNGOPT LOCCLF /home/c.blanes/FlexAID2/Binding_sites/binding_site.pdb OPTIMZ 9999 - -1 OPTIMZ 9999 - 0 OPTIMZ 9999 - 1 OPTIMZ 9999 - 2 OPTIMZ 9999 - 3 OPTIMZ 9999 - 4 ... """ names = ['foo', 'bar', 'baz'] for idx, name in enumerate(names, 1): with open('CONFIG{}.inp'.format(idx), 'w') as outfile: outfile.write(template.format(ligand=name))