更新时间:2023-11-28 19:17:16
不是您要求的内容,但也许你想要的是 os.isatty(sys.stdout.fileno())
,它告诉 stdout
(大致而言)连接到终端。如果将输出传递到文件或另一个进程,或者从cron运行进程,则它将为false。
Not quite what you asked, but maybe what you want is os.isatty(sys.stdout.fileno())
, which tells if stdout
is connected to (roughly speaking) a terminal. It will be false if you pipe the output to a file or another process, or if the process is run from cron.