Search code examples
pythoncharacter-encodingasciiblocknon-ascii-characters

Python: block character will not print


In IDLE, print(chr(219)) (219's the block character) outputs "Û".

Is there any way to get it to output the block character instead?

This might actually be some sort of computer-wide problem, as I cannot seem to get the block character to print from anywhere, copying it out of charmap and into any textbox just results in the Û.


Solution

  • Use the correct character set.

    3>> print(bytes((219,)).decode('cp437'))
    █
    3>> ord(bytes((219,)).decode('cp437'))
    9608
    3>> hex(9608)
    '0x2588'
    3>> print('\u2588')
    █
    

    Unicode Character 'FULL BLOCK' (U+2588)