Mac OS X上完全清除的终端,没有退出Python脚本

问题描述 投票:1回答:1

[我正在使用Python3运行一个简单的实用程序,该实用程序接受用逗号,制表符或竖线分隔的文本输入(通常从csv复制),并在“ |”周围加入文本以提高可读性。

提交空输入后,终端应清除以准备下一次输入。

这在Fedora 31上非常有效,但是在OS X上,终端只是向下移动以隐藏其余文本,而不是实际清除它。我尝试使用“清除”,“ tput重置”,但不确定为什么这不起作用。如果我在Perl中使用system(“ tput reset”)而不是Python,它将正确清除OS X上的终端。

from os import system
import re

def clearScreen():
    system('tput reset')


clearScreen()

while True:
    block = []
    line = '_'

    while line:
        line = input('')
        if len(line) > 0:
            block.append(line)
        else:
            clearScreen()

    for row in block:
        print(' | '.join(re.split('[|,\t]', row)) + '\n')
python python-3.x macos terminal
1个回答
0
投票

这是Mac的怪癖。

改为使用system("printf '\\33c\\e[3J'"),它将起作用。

© www.soinside.com 2019 - 2024. All rights reserved.