[issue39379] sys.path[0] is already absolute path
New submission from Ken Sato <ksato9700@gmail.com>: In the "What’s New In Python 3.9" (Doc/whatsnew/3.9.rst), it says
Python now gets the absolute path of the script filename specified on the command line (ex: python3 script.py): the __file__ attribute of the __main__ module and sys.path[0] become an absolute path, rather than a relative path.
However, I believe sys.path[0] is already absolute path since the previous versions. We can probably remove "and sys.path[0]" from the phrase to avoid possible confusions. ---------- assignee: docs@python components: Documentation messages: 360239 nosy: docs@python, ksato9700 priority: normal severity: normal status: open title: sys.path[0] is already absolute path versions: Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
Change by Karthikeyan Singaravelan <tir.karthi@gmail.com>: ---------- nosy: +vstinner _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
STINNER Victor <vstinner@python.org> added the comment: Correct, it seems like sys.path[0] was already absolute and so it can be removed from What's New in Python 3.9. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
Brett Cannon <brett@python.org> added the comment: Is sys.path[0] always absolute, or is it just a side-effect of the site module (i.e. is it absolute even with -S)? ---------- nosy: +brett.cannon _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
Change by Ananthakrishnan <ananthakrishnan15.2001@gmail.com>: ---------- keywords: +patch pull_requests: +17941 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18561 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment: New changeset 1f0cd3c61a5ae3aac5ebaccc75ae9828ca4f96c4 by Ananthakrishnan in branch 'master': bpo-39379: Remove reference to sys.path[0] being absolute path in whatsnew (GH-18561) https://github.com/python/cpython/commit/1f0cd3c61a5ae3aac5ebaccc75ae9828ca4... ---------- nosy: +xtreak _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment: I have merged the doc change since it's minor. I will leave this open for clarification regarding Brett's question. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
STINNER Victor <vstinner@python.org> added the comment:
Is sys.path[0] always absolute, or is it just a side-effect of the site module (i.e. is it absolute even with -S)?
The absolute path is computed way before the site module is imported. In Python 3.8, _PyPathConfig_ComputeSysPath0() computes sys.path[0] from sys.argv[0]. If the command line contains a script filename, this function uses realpath() on Unix and GetFullPathNameW() on Windows to get the absolute path. If -m is used, getcwd() is called. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
Change by STINNER Victor <vstinner@python.org>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue39379> _______________________________________
participants (5)
-
Ananthakrishnan
-
Brett Cannon
-
Karthikeyan Singaravelan
-
Ken Sato
-
STINNER Victor