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 PMCépagrave
11 AnswersNew 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 https://stackoverflow.com/questions/6850486/how-do-i-specify-extended-ascii-i-e-range256-in-the-python-magic-encoding-s 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 : https://code.sololearn.com/clu3BZvWpOjE/#py This one always returns an encoding error: https://code.sololearn.com/c3Sl3a4IY9qz/#py 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'))