[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Strip lines from files

Francesco Pietra

1/7/2008 3:46:00 PM

I am posting again as previous identical message had alleged suspicious header.

I used successfully script

f=open("prod1-3_no_wat_pop.pdb", "r")
for line in f:
line=line.rstrip()
if "WAT" not in line:
print line
f.close()

to strip lines containing the word WAT from a very long file.

A variant need has now emerged, to perform the same task from a very long
series of shorter files trp.pdb.1, trp.pdb.2 ,..... Could you see how to adapt
the above script to the new need?

Or adapt

grep -v WAT trp.pdb.1

grep -v WAT trp.pdb.2

.....................

grep -v WAT trp.pdb.n

Unless you can think better to remove that pervasive molecule of water, to
avoid performing the calculation ex novo.

Thanks

francesco pietra


____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypa...

1 Answer

Steve L

1/10/2008 2:43:00 PM

0

Francesco Pietra wrote:
> I am posting again as previous identical message had alleged suspicious header.
>
> I used successfully script
>
> f=open("prod1-3_no_wat_pop.pdb", "r")
> for line in f:
> line=line.rstrip()
> if "WAT" not in line:
> print line
> f.close()

log = [[line for line in file(filename,'r') if line.find('WAT')=-1] for
filename in filenamelist]
print log

You can populate filenamelist however you like, e.g. with a command-line
wildcard into sys.argv, or with a os.listdir lookup as in

filenamelist = [filename for filename in os.listdir('.') if
filename.find('.pdb.')]

Caleb