bpo-20443: _PyConfig_Read() gets the absolute path of run_filename by vstinner · Pull Request #14053 · python/cpython (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation2 Commits2 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

vstinner

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.

https://bugs.python.org/issue20443

@vstinner

@vstinner

@ncoghlan: Does this change seem reasonable to you?

Effect of my PR 14053 using script.py:

import sys
print(f"{__file__=}")
print(f"{sys.argv=}")
print(f"{sys.path[0]=}")

Before:

$ ./python script.py 
__file__=script.py
sys.argv=['script.py']
sys.path[0]=/home/vstinner/prog/python/master

With this change:

$ ./python script.py 
__file__=/home/vstinner/prog/python/master/script.py
sys.argv=['/home/vstinner/prog/python/master/script.py']
sys.path[0]=/home/vstinner/prog/python/master

@vstinner

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.

@vstinner

lisroach pushed a commit to lisroach/cpython that referenced this pull request

Sep 10, 2019

@vstinner @lisroach

…ythonGH-14053)

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, sys.argv[0] and sys.path[0] become an absolute path, rather than a relative path.

DinoV pushed a commit to DinoV/cpython that referenced this pull request

Jan 14, 2020

@vstinner @DinoV

…ythonGH-14053)

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, sys.argv[0] and sys.path[0] become an absolute path, rather than a relative path.

@1st1 1st1 mentioned this pull request

Sep 6, 2023