In a python script, is there any way to tell if the interpreter is in interactive mode? This would be useful, for instance, when you run an interactive python session and import a module, slightly different code is executed (for example, log file writing is turned off, or a figure won't be produced, so you can interactively test your program while still executing startup code so variables etc. are declared)
I've looked at http://stackoverflow.com/questions/640389/tell-whether-python-is-in-i-mode and tried the code there, however, that function only returns true if python has been invoked with the -i flag and not when the command used to invoke interactive mode is python
with no arguments.
What I mean is something like this:
if __name__=="__main__":
#do stuff
elif __pythonIsInteractive__:
#do other stuff
else:
exit()