From a51db306de4a95967275d105d2acfca1d66e36d5 Mon Sep 17 00:00:00 2001 From: Joshua-Ward1 Date: Wed, 10 Dec 2025 01:41:09 -0500 Subject: [PATCH] Doc: clarify -i interaction with PYTHONSTARTUP --- Doc/using/cmdline.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index aff165191b76e8..b1112a9a48c89e 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -302,7 +302,8 @@ Miscellaneous options .. option:: -i - Enter interactive mode after execution. + Enter interactive mode after execution, or force interactive mode even when + :data:`sys.stdin` does not appear to be a terminal. Using the :option:`-i` option will enter interactive mode in any of the following circumstances\: @@ -310,8 +311,13 @@ Miscellaneous options * When the :option:`-c` option is used * When the :option:`-m` option is used - Interactive mode will start even when :data:`sys.stdin` does not appear to be a terminal. The - :envvar:`PYTHONSTARTUP` file is not read. + In these "execute then interact" cases, Python runs the script or command + first and does not read the :envvar:`PYTHONSTARTUP` file before entering + interactive mode. + + When :option:`-i` is used only to force interactive mode despite redirected + standard input (for example, ``python -i < /dev/null``), the interpreter + enters interactive mode directly and reads :envvar:`PYTHONSTARTUP` as usual. This can be useful to inspect global variables or a stack trace when a script raises an exception. See also :envvar:`PYTHONINSPECT`.