Recursive insertion of a line
Francesco Pietra
chiendarret at yahoo.com
Wed Nov 21 04:17:51 EST 2007
--- Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Tue, 20 Nov 2007 01:16:53 -0800 (PST), Francesco Pietra
> <chiendarret at yahoo.com> declaimed the following in comp.lang.python:
>
>
> >
> > Now, "file .out" had "TER" inserted where I wanted. It might well be that
> it
> > was my incorrect use of your script.
> >
> Well, it looks like, for purposes of demonstration, the supplied
> program is using "print" statements, which write to stdout. Not sure why
> you needed some sort of pipe/tee call, a simple "> new.output.file"
> redirection would have done.
I used "2>&1 | tee" because in many cases I want to check the screen. That in
ab initio computations, where solving the matrix allows ample vision of the
screen. I agree that for the scope of this python script it is redundant.
>
> > (2) An extra line is inserted (which was not a problem of outputting the
> file
> > as I did), except between "TER" and the next line, as shown below:
> >
> A result of using "print"... "print" adds a newline on the data --
> but ".readline()" does not /remove/ the newline on the input data -- so
> unmodified lines now end with two newlines..
>
> A common .strip() call on those lines might be sufficient...
It is indeed. After a few trials (I am quite new to Python and I rarely find
time for programming, but this attitude might change with Python), the
following script fulfills the scope:
f=open("output.pdb", "r")
for line in f:
line=line.rstrip()
if line:
print line
f.close()
Thanks
francesco
> Or
> change the "print" statements to "sys.stdout.write(...)", and ensure
> that the "TER" is written /with/ a newline ("TER\n").
> --
> Wulfraed Dennis Lee Bieber KD6MOG
> wlfraed at ix.netcom.com wulfraed at bestiaria.com
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: web-asst at bestiaria.com)
> HTTP://www.bestiaria.com/
> --
> http://mail.python.org/mailman/listinfo/python-list
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
More information about the Python-list
mailing list