See here: https://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode
See here:
https://stackoverflow.com/questions/2356399/tell-if-python-is-in-interactive-mode