从文本文件中提取数据的问题 [英] problem in extracting the data from text file
本文介绍了从文本文件中提取数据的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 python 新手,我想从这种格式中提取数据
i am new to python , and I want to extract the data from this format
FBpp0143497 5 151 5 157 PF00339.22 Arrestin_N Domain 1 135 149 83.4 1.1e-23 1 CL0135
FBpp0143497 183 323 183 324 PF02752.15 Arrestin_C Domain 1 137 138 58.5 6e-16 1 CL0135
FBpp0131987 60 280 51 280 PF00089.19 Trypsin Domain 14 219 219 127.7 3.7e-37 1 CL0124
到这种格式
FBpp0143497
5 151 Arrestin_N 1.1e-23
FBpp0143497
183 323 Arrestin_C 6e-16
我已经写了代码希望它能工作但它不起作用,请帮忙!
I have written code in hope that it works but it does not work , please help!
file = open('/ddfs/user/data/k/ktrip_01/hmm.txt','r')
rec = file.read()
for line in rec :
field = line.split("\t")
print field
print field[:]
print '>',field[0]
print field[1], field[2], field[6], field[12]
hmmtext 文件是
the hmmtext file is
FBpp0143497 5 151 5 157 PF00339.22 Arrestin_N Domain 1 135 149 83.4 1.1e-23 1 CL0135
FBpp0143497 183 323 183 324 PF02752.15 Arrestin_C Domain 1 137 138 58.5 6e-16 1 CL0135
FBpp0131987 60 280 51 280 PF00089.19 Trypsin Domain 14 219 219 127.7 3.7e-37 1 CL0124
推荐答案
要逐行遍历文件,您应该这样做:
to iterate over a file line-by-line, you should do:
with open(fname) as file:
for line in file:
fields = line.split('\t')
print(fields) # select fields you want to print
这篇关于从文本文件中提取数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文