[Tutor] A Multiple Concatenation Problem

Stephen P. Molnar s.molnar at sbcglobal.net
Sat Sep 19 18:26:34 EDT 2020



On 09/19/2020 05:36 PM, Mark Lawrence wrote:
> On 19/09/2020 22:09, Stephen P. Molnar wrote:
>
>>
>>     input              output
>> <ligand>  ----> ligand .i.log   where i in range(1,11)
>>
>
> So you want:-
>
> ligand1.1.log
> ligand1.2.log
> ligand1.3.log
> ...
> ligand31.8.log
> ligand31.9.log
> ligand31.10.log
>
> in which case you need nested loops something like:-
>
> filenames = []
> with open('Ligand.list') as infile:
>     for ligand in infile:
>         for suf in range(1, 11):
>             filename = f"{ligand[:-1]}.{suf}.log" # IIRC how to strip 
> EOL :)
>             filenames.append(filename)
>             print(filename)
>
> Have we got there?
>
Exactly what I'm after at this point.

The results of your suggestion (sshorten a bit):

2-Phloroeckol.1.log
2-Phloroeckol.2.log
2-Phloroeckol.3.log
2-Phloroeckol.4.log
2-Phloroeckol.5.log
2-Phloroeckol.6.log
2-Phloroeckol.7.log
2-Phloroeckol.8.log
2-Phloroeckol.9.log
2-Phloroeckol.10.log
7-Phloroeckol.1.log
7-Phloroeckol.2.log
7-Phloroeckol.3.log
7-Phloroeckol.4.log
7-Phloroeckol.5.log
7-Phloroeckol.6.log
7-Phloroeckol.7.log
7-Phloroeckol.8.log
7-Phloroeckol.9.log
7-Phloroeckol.10.log
Aloeemodin.1.log
Aloeemodin.2.log
<...cut...>
Vescalagin.10.log
.1.log    |
.2.log    |
.3.log    |
.4.log    |
.5.log    |     <-- not sure where these came from, but the rest is 
exactly what I wannted.
.6.log    |
.7.log    |
.8.log    |
.9.log    |
.10.log  |

Many thanks.

-- 
Stephen P. Molnar, Ph.D.
www.molecular-modeling.net
614.312.7528 (c)
Skype:  smolnar1



More information about the Tutor mailing list