+ 1

Weird Output

Hi everybody, the output of this code https://code.sololearn.com/cPl8nw6Xn7Mu/#py is showing chars out of the given assumption. Ex. output: 7nI6MebN^{Qæd!0 or uKXykhwû%Gdb=p2 æ nor û shouldn't be in the outcome. Any help or suggestions?

20th Sep 2019, 3:09 PM
Qwerty Sharp
Qwerty Sharp - avatar
2 Antworten
+ 5
hi, there are 2 characters in your string "str" that causes some trouble in playground: ‘ 8216 – 8211 you can see here the character, followed by the character code (something like ASCII code). as you can see it is cade 8216 for the single quote and 8211 for the dash. So these are not the regular ones that should be used. The regular code for ' is 39 and for the dash its 45. I am not sure how you got them in there? Anyway, using this in a regular IDE does work and does not create the characters you mentioned, but if you use this as part of a password it can create problems at a server for exmaple. In sololeran playground you do not have the full range of characters availlable, but you can switch it to utf-16 with the following code at the top of your code: import sys import codecs sys.stdout = codecs.getwriter('utf_16')(sys.stdout.buffer, 'strict')
20th Sep 2019, 3:41 PM
Lothar
Lothar - avatar
+ 1
Thanks Lothar, the problem, as you guessed right, was the copy/past I did to got the special characters (unspecified origin, couldn't remember where). I will consider and save your utf-16 tip for the future.
20th Sep 2019, 4:04 PM
Qwerty Sharp
Qwerty Sharp - avatar