4
votes

I use python on Mac OS X, and I want to use an extended ASCII symbol #219 like in this table :

https://theasciicode.com.ar/extended-ascii-code/block-graphic-character-ascii-code-219.html

The problem, I found out that 'block' character doesn't exist in Mac ASCII... I'm not sure.

Can anyone help me? I was trying to print using unichr(219), but it was giving me different result. It will output Û. What i want is

4
"Extended ASCII" is not standardized, and it varies from platform to platform. AFAIK, The block isn't part of the xASCII of Macs. I'm not even sure how to access it from a modern PC, although I used this block character a lot for MS-DOS programming. - jpaugh
You are wrong, it is standarized in ISO 8859, it depends on the encoding/codepage the user picked. - KurzedMetal
Thanx for the answers, btw @KurzedMetal, i've been searching google, if it's standarized , why couple tables i found have different extended ascii. i found more than 3 asci tables which have extended ascii different to each other. I'm confused. - andio

4 Answers

13
votes

the corresponding unicode character is 0x2588, so use that:

print unichr(0x2588)        # or:
print u"\u2588"

should give you the right result. if you want it in a different encoding, you can always encode it.

6
votes

The character you posted isn't 219, it's 9608. And printing it should work fine:

python3:

>>> ord("█")
9608
>>> chr(9608)
'█'

python2:

>>> unichr(9608)
u'\u2588'
>>> print(u'\u2588')
█

if you still have troubles, set your teminal to use utf-8 and .encode() to utf-8 if neccessary.

2
votes

That character doesn't exist the Extended ASCII table for Mac, however the unicode representation will work.

0
votes

While the rest of the comments were correctly pointing out technical Python side, there is some details for ASCII explanation.

When you're using programming language, you almost always deal with Unicode, and the important thing is that Unicode encoding is different from ASCII. So you need to check Unicode table, like Wiki or Unicode Table.

What you saw in your code is Û which is exactly the Unicode symbol 219 / 0xDB. And what you wanted is which is Unicode Block symbol 9608 / 0x2588