+ 1

Unicode Characters in Code Playground

Hi! :) Got this error: UnicodeEncodeError: 'charmap' codec can't encode character Any chance to use unicode characters in my python code in sololearn. I have some escape sequences in my code. The program runs without a problem on my linux box, but I know character encoding can be a bit tricky.

31st Mar 2018, 11:35 PM
Chris
Chris - avatar
8 ответов
+ 4
You can try fiddling with the codepage and you might chance upon one with acceptable output: https://code.sololearn.com/c6NQFsmNHz82/?ref=app
1st Apr 2018, 4:05 AM
Kirk Schafer
Kirk Schafer - avatar
+ 4
(Actually, there might be a solution to this now if you're still around; not escape sequences but unicode)
28th May 2018, 9:51 PM
Kirk Schafer
Kirk Schafer - avatar
+ 4
Add these two lines to the top of your program: import sys, codecs sys.stdout = codecs.getwriter('utf_16')(sys.stdout.buffer, 'strict') and then use any of these to get unicode chars: "\u0000 \U00000000" chr(9000) chr(0x590) ...or just paste the chars directly: print("🌠") Not all characters will be supported on all devices and I'm not sure if strings like u"..." are required (I didn't need them). I have this code trying to be a block-by-block browser if you like: https://code.sololearn.com/csTae6tX7D4l/?ref=app Disable / comment addTestChars...line 16 if you just want the table.
28th May 2018, 11:40 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
In sololearn code playground context, not all unicode characters are well handled, unfortunatly... The reason is maybe in the limitation due to the way of script execution are handled in sololearn : by buffering in/output and executing/compiling code on server side ^^
1st Apr 2018, 12:11 AM
visph
visph - avatar
+ 1
Thanks for your answers! I think my codesnippet won't work in sololearn. But I learned some new things about character encoding now. :)
1st Apr 2018, 2:58 PM
Chris
Chris - avatar
+ 1
Hi Kirk, still around, still interested :)
28th May 2018, 10:00 PM
Chris
Chris - avatar
+ 1
Thanks Kirk! I will give it a try.
29th May 2018, 4:14 AM
Chris
Chris - avatar