简体   繁体   English

如何在Python控制台中查看以前的打印值

[英]How to see the previous printed values in Python console

I am printing some set of values in console and this is a program which runs for than an hour. 我正在控制台中打印一些值,这是一个运行了一个多小时的程序。 There were run time warning in red during the run. 在运行过程中,运行时间警告显示为红色。 However, when I scroll up to see them, they don't appear, as the program is running very fast displaying new values as it runs. 但是,当我向上滚动以查看它们时,它们不会出现,因为程序运行非常快,并在运行时显示新值。

Is there any way for me to display only run time warnings alone or to see the entire values printed previously (as they are warnings, it does not stop the program from running)? 有什么办法让我仅显示运行时警告或查看以前打印的全部值(因为它们是警告,因此不会阻止程序运行)?

I don't know how you are "printing some set of values" in your console but if you are using the python logging module and your "warnings" are set with the WARN level (all your other stuff is INFO , or DEBUG etc) you can set the logger to only output for WARN and above ( ERROR and CRITICAL ). 我不知道您如何在控制台中“打印一些值”,但是如果您使用的是python logging模块,并且您的“警告”设置为WARN级别(所有其他内容均为INFODEBUG等)您可以将记录器设置为仅WARN及更高版本的输出( ERRORCRITICAL )。

import logging
logger = logging.getLogger('spam_application')
logger.setLevel(logging.WARN)

See more examples in the logging cookbook . 请参阅日志记录手册中的更多示例。

Another option is to set the history of your terminal (I don't know what you're using so can't give exact instructions) to store more lines of your command line. 另一个选择是设置终端的历史记录(我不知道您使用的是什么,因此无法给出确切的说明)来存储命令行的更多行。

Finally you could pipe the output to grep (if using a *NIX system) looking for warning or similar: 最后,您可以将输出通过管道传递到grep (如果使用* NIX系统),以查找warning或类似信息:

python your_script.py | grep warning

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用快捷方式在Pycharm Python控制台中查看完整的先前命令 - How to see the full previous command in Pycharm Python console using a shortcut Python:如何查看是否已打印所有行? - Python : How to see if all rows were printed? 如何使用 python 将控制台中的打印行附加到 QPlainTextEdit 中? - How do I append printed lines from console into a QPlainTextEdit with python? 如何在python中将打印的控制台输出保存到pandas数据框? - How to save printed console output to pandas dataframe in python? 如何将打印在终端控制台上的 output 存储到 Python 中的文本文件中 - How to store output printed on terminal console to a text file in Python 如何比较 python 中的一对值,看下一个值是否大于前一个值? - How to compare a pair of values in python, to see if the next value in pair is greater than the previous? 如何覆盖以前的打印文本? - How to overwrite previous printed text? 如何在控制台中查看代码 [Python, Tkinter, Atom] - How to see code in the console [Python, Tkinter, Atom] PySide 如何在 python 控制台中查看 QML 错误? - PySide How to see QML errors in python console? 如果前一个打印值与新值相同,如何在 python 中打印上一行? - How to print over the previous line in python if the previous printed value is the same as the new one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM