What is the difference between "inspect" and "interactive" flags? The sys.flags function prints both of them.
How can they both have "-i" flag according to the documentation of sys.flags?
How can I set them separately? If I use "python -i", both of them will be set to 1.
man python
says about the-i
flag:Hence
-i
allows inspection of a script in interactive mode.-i
implies both of these things.You can be interactive without inspecting (namely by just callingpython
, without arguments), but not vice versa.According to pythonrun.c corresponding
Py_InspectFlag
andPy_InteractiveFlag
are used as follows:Python doesn't exit on
SystemExit
if "inspect" flag is true.If "interactive" flag is false and current input is not associated with a terminal then python doesn't bother entering "interactive" mode (unbuffering stdout, printing version, showing prompt, etc).
-i
option turns on both flags. "inspect" flag is also on ifPYTHONINSPECT
environment variable is not empty (see main.c).Basically it means if you set
PYTHONINSPECT
variable and run your module then python doesn't exit on SystemExit (e.g., at the end of the script) and shows you an interactive prompt instead of (allowing you to inspect your module state (thus "inspect" name for the flag)).