Help ! it's about ascii characters in the CodePlayground | Sololearn: Learn to code for FREE!


Help ! it's about ascii characters in the CodePlayground

I'm using python in the CodePlayground, and here is my question : When I try to print all usable characters, I'm tempted to write: for i in range(256): print(i, chr(i)) this results in getting : ---- all 128 first characters printed ---- and then : "UnicodeEncodeError: 'charmap' codec can't encode character" Ok, but then if I try : print(chr(230)) It gives me :"µ" printed nicely. print(chr(256)) is the limit. Do you understand what's happening here ? And also, if you know a way to use other encodings/charsets inside CodePlayground (I think there's no way) with python, don't forget to tell me : ) What's the situation with other languages about this limitation ?

1/25/2018 7:34:43 PM


11 Answers

New Answer


You can run this to check which chr() work for i in range(257): try: print(i, chr(i)) except: pass


I think it's worth a shot - no harm in asking 🙂


ASCII is actually 7 bits so it's 128 characters. You are talking about extended ASCII or EASCII that have 8 bits. This could help Edit: It’s 7bits and 8bits not bytes


Of course ! great ! Thank you David !


Do you think it's something we could ask SL team about ? It would be so nice if they could allow the use of the UTF-8 table ...


Ok, I'll write a mail, thank you again, David !


That gives us the answer : Ascii char usable in Codeplayground are : 0-127 160-255 everything from 128 to 159 is not decoded !


I've tried something to try to understand a little more : This code works sometimes : This one always returns an encoding error: Any idea ?


Well, it seems that only some characters won't work, that's why the range() function does not work ! I'll try to catch the bad guys when I have some time for hunting and I'll tell you.


@Toni Isotalo Thanks for answering and sharing this ! So now I understand there's a difference between 0-127 and 128-255 tables, ASCII and EASCII. But still, I don't understand why it sometimes work, sometimes not, with EASCII in the CodePlayground ?


I think it works when you encode it to utf-8. Try this print(i, chr(i).encode('utf-8'))