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

后端 未结 4 1228
情话喂你
情话喂你 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:13

    If you already have extracted the line, you can split it using line.split(). This will give you a list, of which you can extract all the elements you need:

    >>> test='HELIX 2 2 CYS A 97'
    >>> test.split()
    ['HELIX', '2', '2', 'CYS', 'A', '97']
    >>> test.split()[3]
    'CYS'
    

提交回复
热议问题