[Tutor] A Multiple Concatenation Problem
Mats Wichmann
mats at wichmann.us
Thu Sep 17 13:54:46 EDT 2020
On 9/17/20 11:39 AM, Stephen P. Molnar wrote:
>
> I have a Computational Chemisry Problem where I generate a large number
> of text files with names differing only in an index in the file suffix
> of the form <ligand>.$i.log.
>
> My problem is how do I go from <ligand> to <ligand>.$i.log where '$i" is
> iterated from 1 to 10. in a subsequent section of the pytho script?
>
> All that Google does is increase my confusion.
>
> Finally, this is not a school assignment, nor do I wish t initiate a
> string of nasty comments/. What I am looking for is a point in the
> appropriate direction.
This should show the style - the filename you want to open is just a
string, and you can construct that string in a variety of ways. This
particular one uses so-called F-strings to do it:
>>> 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
More information about the Tutor
mailing list