reading a specific column from file
Hai Vu
wuhrrr at gmail.com
Thu Jan 17 04:47:20 EST 2008
Here is another suggestion:
col = 2 # third column
filename = '4columns.txt'
third_column = [line[:-1].split('\t')[col] for line in open(filename,
'r')]
third_column now contains a list of items in the third column.
This solution is great for small files (up to a couple of thousand of
lines). For larger file, performance could be a problem, so you might
need a different solution.
More information about the Python-list
mailing list