Skip to content

Commit b3035ff

Browse files
bobzininbobzinin
authored andcommitted
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
1 parent d4fa707 commit b3035ff

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Doc/using/cmdline.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ source.
159159
containing that file is added to the start of :data:`sys.path`, and the
160160
file is executed as the :mod:`__main__` module.
161161

162+
If the script name refers to a link, the behavior depends on the link
163+
type and operating system. On Unix-like systems, symbolic links are
164+
resolved to the target file's directory when added to :data:`sys.path`.
165+
Hard links use the link's own directory. On Windows, both hard links
166+
and symbolic links use the link's own directory.
167+
162168
If the script name refers to a directory or zipfile, the script name is
163169
added to the start of :data:`sys.path` and the ``__main__.py`` file in
164170
that location is executed as the :mod:`__main__` module.

0 commit comments

Comments
 (0)