[Tutor] how to read two files and substitute

Emile van Sebille emile at fenx.com
Tue May 17 17:53:47 CEST 2011


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



More information about the Tutor mailing list