That is not how split() works, it splits the line up by the given parameter, the way you are using it, it would split the lines where ever it encounters a ',', but you want to replace every space with your ',', that way you would need something like this:
Code:
f = open("List", "r") #open and read file
returnline = [] #empty list
for line in f.readlines():
returnline.append(re.compile(' ').sub(',', line[0:-1]))
as an explanation, the
will set it to be active at every space found, the
Code:
.subn(',', line[0:-1])
will substitute every occurence of the activated part (the space) within the line[0:-1] (meaning the line without the trailing '\n') with the comma (',')
Since the line can be accessed as a char array, theres no point in trying to replace '\n' with anything, since it will allways remain as the very last char (index
END-1, thus [0:-1] meaning char array starting from index 0, first char to position -1 from end) beacause when reading from a file, you will allways read to EOF or EOL (end of line) hence where '\n' resides.
Then later on, you can use split() to split at every ',' in your line, if that is what you wishes, but then again, I can't see why it wouldn't be usefull with my usage, where I split it at every space.. It would be the same result, only a few more operations in your solution.