python - reading chunk of table from a txt file -
i have text file contains table below. part other text not of much involvement me.
tmp [%] [kt] [1/dm] [sf] 1 0.10020 -0.0000 -60.0 0.0000 2 14.12826 0.0000 0.0 0.0000 3 4.00802 -120.3636 -6.0 191.5646 4 4.80962 0.0000 0.0 0.0000 ..... i wanted extract portion of text , first 3 columns. wrote code like:
import codecs f = codecs.open("dmp.txt", "r",'utf-16-le') fr = f.readlines() f.close() line in fr: if line.startswith("tmp")... however, not able figure out how read info column- wise , first 3 columns only. ideas?
for line in fr: v = line.split() print " ".join(v[:3])
gives:
tmp [%] [kt] 1 0.10020 -0.0000 2 14.12826 0.0000 3 4.00802 -120.3636 4 4.80962 0.0000 python
No comments:
Post a Comment