I have written a python(2.7) program to retreive data from a table in a database and copy it into a csv file. There are various data in non-printable format(unicode) which contain \n, \r. Because of \n, \r I am not able to retreive the data as it is in the table.
I have tried the following
str.replace('\n','').replace('\r',' ')
str.replace('\n','\\n').replace('\r', '\\r')
but it did not work out
csv code
cur.execute('select * from db.table_name)
with open('test.csv','w') as csv_file:
csv_writer=csv.writer(csv_file)
for row in cur:
print "row = ", count
count = count + 1
newrow=[];
for index in range(0, len(row)):
value= row[index]
if(type(row[index])is str):
value=row[index].replace("\n"," ").replace("\r"," ")
newrow.append(value)
csv_writer.writerow(newrow)
\r\n(they are linebreaks) and why wouldn't the replace work? please post some examples tooprint(repr(value))and add the output, does.replace("\\r"," ")have a different effect?