简体   繁体   English

Python Curses UI打印Unicode

[英]Python Curses UI printing Unicode

Hello I am making a simple Curses UI app I have everything working. 您好,我正在制作一个简单的Curses UI应用程序,一切正常。 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... Python 2不懂Unicode-它只懂字节...

So port to Python3 (Easy unless you are doing Network programming) or start doing 因此,移植到Python3(容易,除非您正在进行网络编程)或开始

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

Everywhere in your code. 您代码中的任何地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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