[Tutor] how to read two files and substitute

Emile van Sebille emile at fenx.com
Tue May 17 16:19:39 CEST 2011


On 5/17/2011 6:42 AM lina said...
> Hi,
>
> For file1:
>
>    5007  O28 CHO   173      35.300  99.430  65.810  1.00  0.0
>    5008  H29 CHO   173      35.680 100.290  66.150  1.00  0.00
>    5009  C1  CHO   174      59.060  12.440  58.680  1.00  0.00
>    5010  C2  CHO   174      59.460  12.480  60.160  1.00  0.00
>    5011  C3  CHO   174      59.590  11.120  60.830  1.00  0.00
>    5012  C4  CHO   174      60.780  10.430  60.160  1.00  0.00
>
> For file2:
>
> 5008 5010 5011
>
> I want to get the $4(column 4) value which has  the $1 value. for
> values in file2
>
> such as the results is 173 174 174
>
> Thanks for any suggestions,
>


It'll help us help you if you show how far along you've come. 
Otherwise, most of us will presume this is a homework assignment, and 
we'd rather help you learn python than do your homework for you.

In short, you'll read the lines from the file, test each line to see if 
it starts with one of the targets, then spilt the fields from the line 
and select the fourth field.  Accumulate those and return the result.

Post your code when you follow up please.

Emile



More information about the Tutor mailing list