[Tutor] A Multiple Concatenation Problem
Stephen P. Molnar
s.molnar at sbcglobal.net
Fri Sep 18 09:34:00 EDT 2020
On 09/17/2020 02:00 PM, Alan Gauld via Tutor wrote:
> On 17/09/2020 18:54, Mats Wichmann wrote:
>
>>>>> for suf in range(1, 11):
>> ... filename = f"<ligand>{suf}.log"
>> ... print(filename)
>> ...
>> <ligand>1.log
>> <ligand>2.log
>> <ligand>3.log
>> <ligand>4.log
>> <ligand>5.log
>> <ligand>6.log
>> <ligand>7.log
>> <ligand>8.log
>> <ligand>9.log
>> <ligand>10.log
>
> In case that's not clear, Mats is using the new
> format-string notation.
> You can use the old style format strings similarly:
>
> fmt = "<ligand>.%d.log"
> for suf in range(1,11):
> print(fmt % suf)
>
> Or append to a list or...
> rather than print...
>
I read the data in with:
filename = 'Ligand.list'
file = open(filename,mode='r')
text = file.read()
file.close()
where Ligand.list, for testing, as at this point I have 31 ligands to
process, contains
2-Pholoeckol
7-Pholoeckol
If I use either:
fmt = "<ligand>.%d.log"
for suf in range(1,11):
print(fmt % suf)
or
for suf in range(1, 11):
filename = f"<ligand>{suf}.log"
print(filename)
I get the same result: 2-Pholoeckol.1.log to 2-Pholoeckol.10.log
7-Pholoeckol.1.log to 7-Pholoeckol.10.log
Obviously I'm missing something very fundamental, and I'm quite embarrassed by that, but how di I get the ligand name rather than <ligand>... ?
--
Stephen P. Molnar, Ph.D.
www.molecular-modeling.net
614.312.7528 (c)
Skype: smolnar1
More information about the Tutor
mailing list