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

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

    Have a look at the CSV library. https://docs.python.org/2/library/csv.html The following code should do the trick

    >>> import csv
    >>> with open('my-file.txt', 'rb') as myfile:
    ...     spamreader = csv.reader(myfile, delimiter=' ', )
    ...     for row in spamreader:
    ...         print row[3]
    

提交回复
热议问题