Read specific column from .dat-file in Python
Question: I have a results.dat file with some data like this:

    
    
    7522126 0   0   0   0   0   0   -419.795    -186.24 1852.86 0.134695    -0.995462   -2.53153
    7825452 0   0   0   0   0   0   -419.795    -186.24 1852.86 0.134695    -0.995462   -2.53153
    8073799 0   0   0   0   0   0   -345.551    -140.711    1819.04 -0.0220266  -0.85992    -2.29598
    

The values are each separated by a tab.

I want to extract the value in e.g the 8th column for every single line, and
save it to an array. So the output should be this:

    
    
    -419.795
    -419.795
    -345.551
    

What's the easiest way to accomplish this?


Answer: You could use [csv module](https://docs.python.org/3/library/csv.html).

    
    
    import csv
    with open('file') as f:
        reader = csv.reader(f, delimiter="\t")
        for line in reader:
            print(line[7])
    

