从Python [Eclipse]清除命令行输出 [英] Clear command line output from Python [Eclipse]

查看:269
本文介绍了从Python [Eclipse]清除命令行输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse编写Python,我想要能够轻松地清除屏幕。我已经看到这个问题,并尝试(其中建议)以下解决方案

I'm using Eclipse for writing Python, and I want to be able to easily clear the screen. I've seen this question, and tried (among other things suggested there) the following solution

import os

def clear():
    os.system('cls' if os.name == 'nt' else 'clear')

但它没有'完全解决我的问题。而不是清除屏幕,例程会在Eclipse中的命令输出窗口中打印一个小的正方形(好像想打印一个未知的字符)。

but it doesn't entirely solve my problem. Instead of clearing the screen, the routine prints a small square (as if wanting to print an unknown character) to the command output window in Eclipse.

键入 cls 在命令行中工作得很好,运行Python脚本与上述代码从命令行运行。但是如何在Eclipse中看起来不错?

Typing cls in the command line works perfectly fine, as does running a Python script with the above code from command line. But how can I make it look nice in Eclipse as well?

推荐答案

在eclipse中运行它的问题是 cls 使用ANSI转义序列来清除屏幕。我的意思是要清除屏幕, cls 写入一个字符串,如\033 [[80; j到输出缓冲区。本机控制台(eclipse之外的)将此解释为一个清除屏幕的命令,但是eclipse控制台不了解它,所以只需打印一个小的正方形,就像打印一个未知字符一样。

The problem with running it in eclipse is that cls uses ANSI escape sequences to clear the screen. What I mean by this is that to clear the screen, cls writes a string such as "\033[[80;j" to the output buffer. The native console (the one outside of eclipse) interprets this as a command to clear the screen, but the eclipse console doesn't understand it, so just prints a small square as if printing an unknown character.

这篇关于从Python [Eclipse]清除命令行输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆