0

OK, I'm new to python. I'm writing data to a file, but it won't write that data to a new line. I'm ending up with a single line file that reads as

2.0/n3.0/n2.0/n3.0/n2.0/n3.0/n2.0/n3.0/n2.0/n3.0/n2.0/n3.0/n2.0/n3.0/n[2.0, 2.0]/n[3.0, 3.0]/n[2.0, 2.0]/n[3.0, 3.0]/n[2.0, 2.0]/n[3.0, 3.0]/n[2.0, 2.0]/n[3.0, 3.0]/n[2.0, 2.0]/n[3.0, 3.0]/n[2.0, 2.0]/n[3.0, 3.0]/n[2.0, 2.0]/n[3.0, 3.0]/n[2.0, 2.0]/n[3.0, 3.0]/n

When I obviously want the /n to create a new line. I'm writing to the file by creating a list of the new data (in the program called new_data) the using the lines:

try:
    file = open(f_data, 'w')
    file.writelines(new_data)
    file.close()
except IOError:
    print 'Coulnt save to file'

I've tried printing out new_data and that also doesn't show the new lines, instead printing

/n[3.0, 3.0]/n', '[2.0, 2.0]/n[3.0, 3.0]/n', '[2.0, 2.0]/n[3.0, 3.0]/n', '[2.0, 2.0]/n[3.0, 3.0]/n', '[2.0, 2.0]/n[3.0, 3.0]/n', '[2.0, 2.0]/n[3.0, 3.0]/n', '[2.0, 2.0]/n[3.0, 3.0]/n', '[2.0, 2.0]/n[2.0, 2.0]/n']

So I'm guessing the problem is in lines like this:

new_data.append(str(CentrX)+'/n'+str(CentrY)+'/n')

which obviously add the data to the list I then write to that file. Any help on this would be great as I've been searching the net for an answer to this problem.

3
Contributors
3
Replies
9
Views
6 Years
Discussion Span
Last Post by DayneD89
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.