In a Python script, is there any way to tell if the interpreter is in interactive mode? This would be useful so that, for instance, when you run an interactive Python sessio
__main__.__file__ doesn't exist in the interactive interpreter:
__main__.__file__
import __main__ as main print hasattr(main, '__file__')
This also goes for code run via python -c, but not python -m.
python -c
python -m