简体   繁体   中英

Python Curses UI printing Unicode

Hello I am making a simple Curses UI app I have everything working. I am trying to print this █ in my progress bar but when I do i get this error

File "simple.py", line 100, in <module>                                                                       │
│           main()                                                             │
│           File "simple.py", line 55, in main                         │
│           show_progress()      │
│           File "simple.py", line 83, in show_progress                                         │
│           win.addstr(1,pos,u"\u2588")          │
│UnicodeEncodeError: 'ascii' codec can't encode character u'\u2588' in position 0: ordinal not in range(128)     

I Know this is a horrible error but it is how it is printed out

Here is the code that is printing it

win.addstr(1,pos,u"\u2588")

Python 2 does not understand Unicode - it only understands bytes...

So port to Python3 (Easy unless you are doing Network programming) or start doing

bytes(unicode_string.encode('utf-8'))

Everywhere in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM