Message399196
In 3.2, the default program name on non-Windows systems was changed to "python3" (see bpo-15020). In 3.5, the code was moved into Python/pylifecycle.c (see bpo-22869). Between 3.7 and 3.8, the initialization code was rewritten (see PEP 587). Currently it's set in config_init_program_name() in Python/initconfig.c. On POSIX systems, calculate_which() in Modules/getpath.c searches PATH to resolve the name if it has no path separator. For example:
$ bash -c 'exec -a "" python -c "import sys; print(repr(sys.executable))"'
'/home/someone/.local/bin/python3'
The default "python3" program name isn't used if C argv[0] is non-empty, in which case calculate_which() may or may not find the given program name:
$ bash -c 'exec -a "ls" python -c "import sys; print(repr(sys.executable))"'
'/usr/bin/ls'
$ bash -c 'exec -a "py" python -c "import sys; print(repr(sys.executable))"'
''
In Windows, the default program name is "python", but this isn't relevant for sys.executable, which is based on GetModuleFileNameW(NULL, ...) instead. This is similar to using readlink("/proc/self/exe", ...) in Linux, except the loader in Windows, and thus GetModuleFileNameW(), does not resolve symlinks in the file path. |
|
Date |
User |
Action |
Args |
2021-08-07 17:33:06 | eryksun | set | recipients:
+ eryksun, loewis, barry, ncoghlan, eric.araujo, Arfrever, r.david.murray, allan, stephane, piotr.dobrogost, iritkatriel |
2021-08-07 17:33:06 | eryksun | set | messageid: <1628357586.48.0.505399593874.issue10835@roundup.psfhosted.org> |
2021-08-07 17:33:06 | eryksun | link | issue10835 messages |
2021-08-07 17:33:06 | eryksun | create | |
|