具有打印功能的Python清除输出控制台? [英] Python Clear Output Console With Print Function?

查看:627
本文介绍了具有打印功能的Python清除输出控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我不知道是否有人知道如何做到这一点,或者即使这是一个正确的问题。但是如何使用python中的print()函数清除输出控制台?

我没有丝毫的线索如何从这个问题开始,但我确实有python的完整python参考3.3.0和是的,我确实使用python 3.3.0



关于这个问题的一些背景信息:

i在blender编码(i上周在blender游戏引擎(版本2.68.0)中编写和调试python脚本,我需要在控制台上打印一些内容,并且当我按下特定键时,搅拌机会清除调试控制台。

现在我知道如何设置击键命令以及所有这些但我不知道该怎么做的部分是我通过print()函数实际清除控制台的部分。

有这种能力将大大提高我在python中的调试技巧,因为有时当我调试一个大脚本时,我可以将大量信息打印到调试控制台上,当没有li时它会变得有点乱ne break。

感谢您提前的帮助,

MasterCodeon

解决方案

而不是使用 print(),使用系统调用可能更容易(虽然显然可以使用print,请参阅PIEBALDconsult的答案)。要执行系统调用,请使用 os.system

  import  os 
os.system(' cls'



cls 仅限Windows。如果你使用Linux或Mac OS,请改用 clear



这是如何工作的? os.system 执行系统调用;所以它调用 cls 命令来清除屏幕。


据说ANSI转义序列仍应在Windows上运行,但我还没有让它工作。



http://forum.codecall.net/topic/59142-how-to-clear-the-console-screen-with-ansi-any-

language /
[ ^ ]



PS

来自我的一些旧C代码(大约1995年),用于兼容VT100兼容的哑终点: printf(\ 033 [H \ 033 [J]

如果上面的博客条目是正确的,这应该适用于Windows 7,但我想知道是否必须启用ANSI兼容性。

没有进一步的研究和测试在Windows 7上发现这个成功。<无线电通信/>


我无法使用它: http:// support。 microsoft.com/kb/101875 [ ^ ]

Hello Everyone!
I don't know if anyone knows how to do this, or even if this is the right place to ask this. But how would one clear the output console using the print() function in python?
I haven't the slightest clue how where to start with this question, but i do have the complete python reference for python 3.3.0 and yes, i do use python 3.3.0

Some background info on this question:
i was coding in blender(i code and debug python scripts in the blender game engine(version 2.68.0) last week and i needed to print something to the console and have blender clear the debugging console when ever i press a specific key.
now i know how to set up the key stroke command and all of that but what i don't know how to do is the part where i actually clear the console via the print() function.
having this ability would greatly improve my debugging skills in python, because sometimes when i am debugging a large script i can have a lot of information being printed onto the debugging console, and it gets kind of messy when there is no line breaks.
thanks for your help in advance,
MasterCodeon

解决方案

Instead of using print(), it might be easier to use a system call (though apparently, using print is possible, see PIEBALDconsult's answer). To execute a system call, use os.system.

import os
os.system('cls')


cls is Windows-only. If you use Linux or Mac OS, use clear instead.

How does this work? os.system executes a system call; so it calls the cls command which clears the screen.


Supposedly ANSI escape sequences should still work on Windows, but I haven't gotten it to work.

http://forum.codecall.net/topic/59142-how-to-clear-the-console-screen-with-ansi-any-
language/
[^]

P.S.
From some of my old C code (circa 1995), for working with a VT100-compatible dumb terminus: printf("\033[H\033[J")
If the above blog entry is correct, this should work on Windows 7, but I wonder whether or not ANSI compatibility has to be enabled or something.
No further research and testing on Windows 7 has found that this succeeds.

I couldn't get this to work either: http://support.microsoft.com/kb/101875[^]


这篇关于具有打印功能的Python清除输出控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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