Python 使用colorama在Windows 10终端窗口中定位光标

Python 使用colorama在Windows 10终端窗口中定位光标,python,python-3.x,terminal,colorama,Python,Python 3.x,Terminal,Colorama,我找到的每一个文档都表明这应该是可行的,但是光标位置不会返回到0,0 colorama.init() def move (y, x): print("\033[%d;%dH" % (y, x)) for file in original_file: for element in root.iter(): all_lines = all_lines+1 if element.text !

我找到的每一个文档都表明这应该是可行的,但是光标位置不会返回到0,0

colorama.init()

def move (y, x):
    print("\033[%d;%dH" % (y, x))

for file in original_file:
        for element in root.iter():
                all_lines = all_lines+1
                if element.text != None:
                    if element.tag in field_list:
                        if len(element.text) > field_list[element.tag]:
                                corrected_lines = corrected_lines+1           
                                move(0, 0)
                                working_message(username, window_width)
                                print("{3}: {0} \n {1} to {2}\n---".format(element.tag, len(element.text), field_list[element.tag], corrected_lines))
                                print(corrected_lines)
                                print(all_lines)

                                element.text = element.text[field_list[element.tag]]

重要的是colorama被初始化,然后每个循环都应该使用move(0,0)函数将光标移动到0,0(作为“\033[0;0H”字符串传递以打印)。

屏幕左上角的坐标是1,1,而不是0,0。因此您的调用应该是

move(1,1)
您的
print()
调用应该如下所示:

print("\033[%d;%dH" % (y, x), end="")
否则,
move(1,1)
将调用
print()
,它将发出转义码将光标发送到所需的坐标,然后立即发出回车/换行符。这将使您的
move(1,1)
有效地变成
move(1,2)