I have a text file named "multipoles.txt", i took a screen shot of it ( http://img193.imageshack.us/i/textf.jpg/) so i can explain myself better. Ok so I basically want to go in the file and get the data from the third column below the text that says Electronic Charge Electrons. The numbers in the columns will not be the same all the time seeing as this is an output file that depends on parameters for a calculation. How can i set python to read that specific column and pass back the data on it...and create another text file with just that column?....The column goes way further down too.
pythonbegginer
0
Newbie Poster
Recommended Answers
Jump to PostThere are several ways. The easiest way is to use a python list. The more complicated way is to use a dictionary. The advantage of the dictionary is that if later down the road, you need to retrieve some of the original information (for example, the entire line that corresponded …
Jump to PostThanks for the help.
I won't need to retrieve the original data. Python will go in through the same file and just grab that column everytime.
I tried your code and it tells me that there is an error in the "for line in file:" line...telling me that there is …
Jump to PostThis is what i have:
import re infile = open ('file', 'r') outfile = open('output', 'w') column = 31 for line in infile: if not re.match('#', line): line = line.strip() sline = line.split() outfile.write(sline[column] + '\n') infile.close() outfile.close()
It seems to now tell me that there is an IndenError: …
All 9 Replies
hughesadam_87
54
Junior Poster
pythonbegginer
0
Newbie Poster
hughesadam_87
54
Junior Poster
pythonbegginer
0
Newbie Poster
hughesadam_87
54
Junior Poster
pythonbegginer
0
Newbie Poster
pythonbegginer
0
Newbie Poster
abhilam
0
Newbie Poster
snippsat
661
Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.