On 12/10/2011 18:21, Anna Olofsson wrote:
Hi,

I'm a beginner at python and I'm trying to extract a specific column from a txt file ( see attached file).

In the attached file I want to extract the entire column/pph2_prob /(i.e. column 16). But I want to get all the values from that column without the headline /pph2_prob.

/How do I accomplish that?

Best,
Anna



Dear Anna,

Using the CSV module should work.

Something along the lines of (untested):

inLines = CSV.DictReader("/path/to/myfile.csv")
data = []
for a in inLines:
    data.append(a)

for line in data:
    print line["/pph2_prob/"]


Once you've got that working you just need to put the results in a file, instead of printing them.

On a practical note (and there may be many reasons why not to), it might be easier to open in a spreadsheet and take the data from there....

HTH,

Matt
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to