Python Forum
unicode weirdness - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: unicode weirdness (/thread-11879.html)



unicode weirdness - Skaperen - Jul-30-2018

this is probably a feature. when i run this code (python3 required):
out = '\n'*8
for n in range(0,1024):
    if n%32 == 0:
        if out:
            print(out)
        out = hex(0x100000000+n)[-8:] + '  '
    if len(repr(chr(n))) < 4:
        out = out + ' ' + chr(n)
    else:
        out = out + ' .'
print(out)
it outputs a bunch of ASCII then a bunch more non-ASCII characters. but starting at line 00000300 a few lines are shorter and more compact, despite the space included between characters (see line 8 in the code). even weirder, at 00000320 and 00000340, characters have backed up over the spaces that came before them.

i am wondering how i can detect this given a character code so i can format my output correctly.


RE: unicode weirdness - DeaD_EyE - Jul-30-2018

I had a similar issue with printing filenames. I have some files with Chinese and other characters, which breaks the formatting.
To fit them in one line, I had to use wcwidth to get the real width of the Unicode chars.
Instead of using the len function to get the width, I used wcwidth.


RE: unicode weirdness - Skaperen - Jul-30-2018

i know there are some double wide characters, but the odd thing is that the space i put between them gets canceled away.