+ 12
How to set equal width of ASCII-characters in Code-Playground's Python-Output?
In my code https://code.sololearn.com/ch8o7903hzHT/?ref=app I have gathered all characters which can be obtained with the chr()-function in Python. As one can see, the width of the characters with numbers of 176 and above differ from the lower ones. Is there a chance to set it to equal width for all of the printable characters, and how would I have to achieve this?
9 Antworten
+ 5
A note: Codes output to pipe (not a rendering device):
https://code.sololearn.com/cG2HfDHa9WGx/#py
* So LunarCoffee's right; SoloLearn would have to change the app (perhaps not as simple as it appears). Instead...
* Python's detecting/set to ASCII (<128) when utf_16 works:
https://code.sololearn.com/csTae6tX7D4l/#py
With the 2 lines for utf_16 you get more options like various Unicode spaces:
http://jkorpela.fi/chars/spaces.html
This may be the way, because we're missing variable-width-handling imports:
ftfy: https://github.com/LuminosoInsight/python-ftfy/blob/master/ftfy/formatting.py
wcwidth: https://pypi.org/project/wcwidth/
Also: When monospace fonts aren't: The Unicode character width nightmare
https://denisbider.blogspot.com/2015/09/when-monospace-fonts-arent-unicode.html
Discuss (HackerNews): https://news.ycombinator.com/item?id=10206380
[outside SL]
Wraps Python's terminal capabilities - see Examples: detect-multibyte.py
http://blessed.readthedocs.io/en/latest/intro.html
+ 4
I'm pretty sure the widths of those characters are defined by the font. Either way, I'm pretty sure there isn't a way to fix this.
+ 4
@ Kirk Schafer
Thank you very much for your information! It is amazing what characters can be displayed in code playground. But that's a little of hard stuff for me at the moment - perhaps tomorrow.
+ 4
You just need these two lines at the top of your program:
import sys, codecs
sys.stdout = codecs.getwriter('utf_16')(sys.stdout.buffer, 'strict')
Then you can print any unicode character you want (in SoloLearn), including just pasting them in from a website.
At home/work for just aligning those ASCII (0-255) characters, you can try changing the font:
https://stackoverflow.com/questions/3592673/change-console-font-in-windows
+ 4
Kirk Schafer
thank you, that's nice to read!
I will try this as soon as possible. :-)
+ 3
@ Tim
Yes, that would be the best solution, I think. ;-)
+ 2
@ tamaslud
I discovered the same today. When I opened code playground on my computer (at work on MS Internet Explorer), all characters have an identical width.
But on my Android phone that's not the case as I mentioned in my initial posting.
+ 1
Programm your own Python Interpreter in an Web document, set the font of the output textfield to mono-space and run it in SL ;)
0
i am strugling with the same thing.
the char output is proper in PC environment, but not on my android phone. i received some notifications earlier, that on some phones the situation is not so critical, there are 2 incoherent chars altogether, which is bearable.
i don't know whether it is phone specific, SL version specific, or OS specific.