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

前端 未结 3 1900
北海茫月
北海茫月 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 16:59

    You should simply add a command-line switch in the scheduled task, and check for it in your script, modifying the behavior as appropriate. Explicit is better than implicit.

    One benefit to this design: you'll be able to test both behaviors, regardless of how you actually invoked the script.

提交回复
热议问题