From b3035ff1626b93d95bc9d531c6716c6c087b014c Mon Sep 17 00:00:00 2001 From: bobzinin Date: Mon, 1 Dec 2025 18:33:41 +0300 Subject: [PATCH] Doc: Clarify sys.path[0] behavior for symbolic and hard links Improve documentation of how Python sets sys.path[0] when the script is accessed via different link types: - On Unix-like systems, symbolic links are resolved to target directory - Hard links and Windows file links use the link's own directory Fixes #58752 --- Doc/using/cmdline.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index aff165191b76e8..d9ae919ac5af44 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -159,6 +159,12 @@ source. containing that file is added to the start of :data:`sys.path`, and the file is executed as the :mod:`__main__` module. + If the script name refers to a link, the behavior depends on the link + type and operating system. On Unix-like systems, symbolic links are + resolved to the target file's directory when added to :data:`sys.path`. + Hard links use the link's own directory. On Windows, both hard links + and symbolic links use the link's own directory. + If the script name refers to a directory or zipfile, the script name is added to the start of :data:`sys.path` and the ``__main__.py`` file in that location is executed as the :mod:`__main__` module.