using python 3.8.1
I am trying to write a string to a csv file. Before I write the string, however, I want to add line breaks into the string.
mystring is a set of values separated by ','. I want to include a line break at every instance there is a number exactly next to a capital letter. e.g(Text,10,0.0Text,9,8.0Text,5.45,2.3) etc..
I want it to write to the csv as:
Text,10,0.0
Text,9,8.0
Text,5.45,2.3
I have tried this so far but to no avail.
newstring = re.sub(r'[0-9][A-Z]', r'[0-9][A-Z]\n', mystring)
with open('new.csv', 'a') as file:
file.write(newstring)
This writes the string to the csv file but there are no line breaks it is all on the first line.
I would appreciate if someone can point me in the right direction.
I am trying to write a string to a csv file. Before I write the string, however, I want to add line breaks into the string.
mystring is a set of values separated by ','. I want to include a line break at every instance there is a number exactly next to a capital letter. e.g(Text,10,0.0Text,9,8.0Text,5.45,2.3) etc..
I want it to write to the csv as:
Text,10,0.0
Text,9,8.0
Text,5.45,2.3
I have tried this so far but to no avail.
newstring = re.sub(r'[0-9][A-Z]', r'[0-9][A-Z]\n', mystring)
with open('new.csv', 'a') as file:
file.write(newstring)
This writes the string to the csv file but there are no line breaks it is all on the first line.
I would appreciate if someone can point me in the right direction.