temperature data extracted.dat has the following list ie
out2=open('final temperature data with lines.dat','w')
my_list=open('temperature data extracted.dat')
my_list_as_string = '\n'.join(str(x) for x in my_list)
I tried to work this way as you mentioned but still out2 has the same format ie ...can you please check my program.
First: Please learn to use the CODE button so your code has line numbers, indentation, etc. Very helpful.
Second, I am not sure of the actual format of the file 'temperature data extracted.dat' That is the key. You must deal with that exact format, whatever it is. I begin to think it is just one very long line, with commas and single quote marks in that line (as well as the "real" data). Is that true?
Third: You need to understand what you want, what you have, and what steps to take to convert from 'have' to 'want'. Just waving someone else's code at it is unlikely to work, much less work well.
Fourth and last: It is important when thinking, and when writing, to keep categories clear; A list is not a file is not a string. For example, thinking about a file while calling it a list leads to confusion for both yourself and your readers.
A single line. OK then the code reads in the one line from the file, into a variable. Say list_as_string = f.readline() . Then you convert that string into an actual list: actual_list = eval(list_as_string.strip()) and finally, you deal with the list elements however you want. Perhaps
with open('output','w') as ofile
This will only work if
The data is in fact all on one line
The data is correctly formatted as the string representation of a list
Before you try to use this code, ask yourself if you understand it. If not, read about the with statement and string's join method