情节和诅咒 - windows

发布于 2025-01-13 19:01:38 字数 1426 浏览 0 评论 0原文

需要此代码的帮助:

import plotext as plt
from contextlib import redirect_stdout
import io
import curses
import locale
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()

PlotFile = io.StringIO()

with redirect_stdout(PlotFile):
    y = plt.sin() # sinusoidal signal 
    plt.scatter(y, marker='dot', )
    plt.title("Scatter Plot")
    plt.plot_size(10, 10)
    plt.show()
PlotFile.seek(0)
w = PlotFile.readlines()
allchar = []
vischar = []
dechar = []
bychar = []
def main (stdscr):
    curses.start_color()
    curses.use_default_colors()
    k = 0
    for i in w:
        for c in i:
            if ord(c) not in allchar:
                allchar.append(ord(c))
                vischar.append(c)
                dechar.append(c.encode('utf-8'))
                bychar.append(bytes(dechar[-1]))
            stdscr.addstr(chr(ord(c)).encode('utf-8'))
        print(i)
        k += 1
   stdscr.refresh()
   curses.napms(3000)

curses.wrapper(main)


print(allchar)
print(vischar)
print(dechar)
print(bychar)

Using VScode on Windows python 3.9 and wincurses。虽然在普通终端上plotext工作正常,但在curses中显示奇怪的字符,如 [[m 、 [[107m 等。尝试了编码和uft混乱,仍然不知道如何解决这个问题。正如我已经发现的那样,curses 默认使用 uft-8,而 python 字符串使用 utf-16 编码,因此必须进行转换。当尝试从 allchar 列表中一一打印所有显示的字符时。但我注意到,curses 中打印了 [ 字符,该字符不在原始plotext 输出中。我认为这是中间某个地方的unicode问题,但仍然找不到。任何帮助将不胜感激。

Needed help with this code:

import plotext as plt
from contextlib import redirect_stdout
import io
import curses
import locale
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()

PlotFile = io.StringIO()

with redirect_stdout(PlotFile):
    y = plt.sin() # sinusoidal signal 
    plt.scatter(y, marker='dot', )
    plt.title("Scatter Plot")
    plt.plot_size(10, 10)
    plt.show()
PlotFile.seek(0)
w = PlotFile.readlines()
allchar = []
vischar = []
dechar = []
bychar = []
def main (stdscr):
    curses.start_color()
    curses.use_default_colors()
    k = 0
    for i in w:
        for c in i:
            if ord(c) not in allchar:
                allchar.append(ord(c))
                vischar.append(c)
                dechar.append(c.encode('utf-8'))
                bychar.append(bytes(dechar[-1]))
            stdscr.addstr(chr(ord(c)).encode('utf-8'))
        print(i)
        k += 1
   stdscr.refresh()
   curses.napms(3000)

curses.wrapper(main)


print(allchar)
print(vischar)
print(dechar)
print(bychar)

Using VScode on Windows python 3.9 and wincurses. While on ordinary terminal plotext working fine, in curses displaying odd characters like [[m , [[107m and others. Tried encoding and uft mess, still can't figure out how to manage this problem. As I already figured out curses use uft-8 by default, while python strings are encoded in utf-16, so conversion must be done. When tried to print each character one by one from allchar list all character displayed. But I noticed, that there is [ character printed in curses, which is not in original plotext output. I think it is unicode problem somewhere in middle, but still can't find. Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜光 2025-01-20 19:01:38

该示例无法在我的计算机上运行,​​但我可以告诉您,plotext 在彩色绘图的 ansi 代码内输出 [
例如,以下字符串为红色:

'\x1b[38;5;1mplotext\x1b[0m'

如果不需要,请尝试使用 clear_color() 方法删除颜色以及不需要的 ansi 代码。祝你好运。

the example does not run on my machine, but I can tell you that plotext outputs [ inside the ansi code of the colored plot.
Here is, for example, the string "plotext" colored red:

'\x1b[38;5;1mplotext\x1b[0m'

If undesired, try the clear_color() method to remove colors and so the undesired ansi codes. Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文