문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top