python - Saving print statement to new file -


new python (should noted). go easy on me.

i have written following isolate specific part of file

for line in open('120301.kap'):     rec = line.strip()     if rec.startswith('ply'):        print line 

the output appears such

ply/1,48.107478621032,-69.733975000000  ply/2,48.163516399836,-70.032838888053  ply/3,48.270000002883,-70.032838888053  ply/4,48.270000002883,-69.712824977522  ply/5,48.192379262383,-69.711801581207  ply/6,48.191666671083,-69.532840015422  ply/7,48.033358898628,-69.532840015422  ply/8,48.033359033880,-69.733975000000  ply/9,48.107478621032,-69.733975000000     

ideally hoping output create csv file coordinates. (the ply/1, ply/2 etc. not need stay). doable? if not, @ least can print statement result in new textfile same name kap file?

this totally doable! here couple links docs: https://docs.python.org/2/library/csv.html #for writing/reading csv. make own csv regular file reading/writing functions.

file = open('data', rw) output = open('output.csv', w) file.write('your infos') #add comma each string output? 

i think should work.


Comments