[英]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
级别(所有其他内容均为INFO
或DEBUG
等)您可以将记录器设置为仅WARN
及更高版本的输出( ERROR
和CRITICAL
)。
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.