How can I check to see if a Python script was started interactively?

前端 未结 3 1901
北海茫月
北海茫月 2020-12-21 16:27

I\'d like for a script of mine to have 2 behaviours, one when started as a scheduled task, and another if started manually. How could I test for interactiveness?

EDI

3条回答
  •  轮回少年
    2020-12-21 17:08

    If you want to know if you're reading from a terminal (not clear if that is enough of a distinction, please clarify) you can use

    sys.stdin.isatty()
    

提交回复
热议问题