I have the following line of code inside a loop that goes through the records of a database table and print out the comment field:
output_file.write("\nTimesheet comment: {}".encode('utf-8').format(timesheet.comments))
it gives the following error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 570: ordinal not in range(128)
The output file also print the following "^M" in several lines. How can I fix this error. Even ignoring strange characters could be an acceptable solution if there is no simple way to go round the error but I don't know how to attach a condition to a .format(...) function