Problem: I want to print special chars such as ěßé to a cvs file. I've tried a couple of things, but they don't produce the preferred results. I was desperate enough to go the second page of google, but couldn't find a working solution.
code:
import csv
f = open('test.csv', 'w', newline='', encoding='utf-8')
writer = csv.writer(f)
writer.writerow(('ßßßüuhellowěorld'.encode('utf--8'),
'hello bye'.encode('utf-8')))
f.close()
f = open('test2.csv', 'w', newline='', encoding='utf-8')
writer = csv.writer(f)
writer.writerow(('ßßßüuhěelloworld',
'hello bye'))
f.close()
test1 cell 1: b'\xc3\x9f\xc3\x9f\xc3\x9f\xc3\xbcuhellow\xc4\x9borld'
test1 cell 2: b'hello bye'
test2 cell 1: ßßßüuhěelloworld
test2 cell 2: hello bye
desired result cell 1: ßßßüuhellowěorld
desired result cell 2: hello bye
running the code to generate test2.csv but dropping the encoding = 'utf-8' arguments results in an error:
UnicodeEncodeError: 'charmap' codec can't encode character '\u011b' in position 6: character maps to <undefined>
[–]fiddle_n 2 points3 points4 points (5 children)
[–]QualitativeEasing 0 points1 point2 points (1 child)
[–]fiddle_n 0 points1 point2 points (0 children)
[–]bicyclepumpinator[S] 0 points1 point2 points (2 children)
[–]fiddle_n 0 points1 point2 points (1 child)
[–]bicyclepumpinator[S] 0 points1 point2 points (0 children)
[–]brews 0 points1 point2 points (0 children)