Insert string into string

Peter Otten __peter__ at
Sun Jul 27 08:41:54 CEST 2008

Mensanator wrote:

> I don't know why you're using stdin if you're reading from a file.

>From Francesco's initial post in his previous thread I inferred that he had
a script like

f = open("xxx.pdb")
for line in f:
    # process line
    print line

and was calling it

python >outfile

My hope was that

import sys
for line in sys.stdin:
    # process line

invoked as

python <xxx.pdb >outfile

would be an improvement as it avoids hardcoding the filename, but instead
chaos ensued...

Francesco: Mensanator's script looks like you can take it "as is". If you
want to use Python to do other interesting things I highly recommend that
you work your way through a tutorial of your choice. This will make
subsequent trial-and-error much more fun.

Following Roy's suggestion I also had a brief look at Biopython's PDB parser
which has the advantage that it "understands" the file format.
Unfortunately it is probably too complex for you to use at this point of
your career as a pythonista ;)

By the way, are you trying to modify the chain ID? Biopython locates that at
position 21, so take this as a reminder that indices in Python start at 0,
i. e. line[21] gives you the 22nd character in the line.


More information about the Python-list mailing list