How to extract specific columns from a space separated file in Python?

后端 未结 4 1261
情话喂你
情话喂你 2021-01-07 06:31

I\'m trying to process a file from the protein data bank which is separated by spaces (not \\t). I have a .txt file and I want to extract specific rows and, from that rows,

4条回答
  •  盖世英雄少女心
    2021-01-07 07:21

    you can expend the key words as you want. the result is list contained line with key words you can do further process of result to get what you want

    with open("your file") as f:
         keyWords = ['HELIX','SHEET','DBREF']
         result = [ line  for line in f for key in keyWords if key in line]
    

提交回复
热议问题