Using print in a python script gives the following result:

10.25, 9.23, 8.97, 8.71, 8.40, 8.36, 8.30, 8.21
10.25, 9.23, 8.97, 8.71, 8.40, 8.36, 8.30, 8.61
0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15
0.60, 0.60, 0.60, 0.60, 0.50, 0.50, 0.50, 0.15
4.85, 2.85, 1.85, 1.25, 0.95, 0.85, 0.80, 0.45
1.35, 1.35, 1.35, 1.35, 1.10, 1.10, 1.10, 0.15
0.60, 0.60, 0.60, 0.60, 0.50, 0.50, 0.50, 0.15
0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.15
2.84, 1.84, 1.08, 0.58, 0.50, 0.25, 0.18, 0.15
26.85, 23.83, 21.57, 20.71, 19.85, 18.71, 17.60, 13.96

What is the easiest way to write/print this to a (csv) file ?

Recommended Answers

All 3 Replies

You could use something like this ...

raw_data = '''\
10.25, 9.23, 8.97, 8.71, 8.40, 8.36, 8.30, 8.21
10.25, 9.23, 8.97, 8.71, 8.40, 8.36, 8.30, 8.61
0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15
0.60, 0.60, 0.60, 0.60, 0.50, 0.50, 0.50, 0.15
4.85, 2.85, 1.85, 1.25, 0.95, 0.85, 0.80, 0.45
1.35, 1.35, 1.35, 1.35, 1.10, 1.10, 1.10, 0.15
0.60, 0.60, 0.60, 0.60, 0.50, 0.50, 0.50, 0.15
0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.40, 0.15
2.84, 1.84, 1.08, 0.58, 0.50, 0.25, 0.18, 0.15
26.85, 23.83, 21.57, 20.71, 19.85, 18.71, 17.60, 13.96
'''

space = ' '
csv_data = ""
for c in raw_data:
     if c != space:
         csv_data += c

print(csv_data)

'''result ...

10.25,9.23,8.97,8.71,8.40,8.36,8.30,8.21
10.25,9.23,8.97,8.71,8.40,8.36,8.30,8.61
0.15,0.15,0.15,0.15,0.15,0.15,0.15,0.15
0.60,0.60,0.60,0.60,0.50,0.50,0.50,0.15
4.85,2.85,1.85,1.25,0.95,0.85,0.80,0.45
1.35,1.35,1.35,1.35,1.10,1.10,1.10,0.15
0.60,0.60,0.60,0.60,0.50,0.50,0.50,0.15
0.40,0.40,0.40,0.40,0.40,0.40,0.40,0.15
2.84,1.84,1.08,0.58,0.50,0.25,0.18,0.15
26.85,23.83,21.57,20.71,19.85,18.71,17.60,13.96

'''

Thanks for your reply, how can I get the result to a file ?

This is how I solved it, maybe not the most elegant way but it works:

    for line in cline:
        outFile.write(line)
    outFile.write('\n')
    outFile.close
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.