[Tutor] how to read two files and substitute

lina lina.lastname at gmail.com
Tue May 17 18:36:07 CEST 2011


Thanks, it works.

On Tue, May 17, 2011 at 11:53 PM, Emile van Sebille <emile at fenx.com> wrote:
> On 5/17/2011 8:31 AM lina said...
>>
>> Following Michiel's code (a little adjustment was done):
>>
>
> Well. you're almost there.  The error you're getting
> is likely due to splitting an empty line, then referencing
> the [1] and [4] elements.
>
> After you split the line into parts, test to confirm
> that the fields you need are there:
>
>> #!/bin/python
>>
>> mapping={}
>> for line in open("confout.pdb").readlines():
>>   parts=line.strip().split()
>
>     if len(parts)>3:
>
>>   mapping[parts[1]]=parts[4]
>
> also, note that python indexes from zero, so this should be
>     mapping[parts[0]]=parts[3]
>
>> origs=open("dummy.atomID").read().split()
>> print " ".join([mapping[orig] for orig in origs])
>
>
> Emile
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Best Regards,

lina


More information about the Tutor mailing list