This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients lkollar, ncoghlan, ned.deily, pablogsal, ronaldoussoren, vstinner
Date 2019-03-18.12:06:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1552910808.49.0.865500869393.issue36236@roundup.psfhosted.org>
In-reply-to
Content
> Omitting it from sys.path in that case makes sense to me, but I'm not sure what sys.argv[0] should be set to.

I propose to use ".". It would be consistent with platforms which doesn't implement realpath:

    if (have_module_arg) {
        #if defined(HAVE_REALPATH) || defined(MS_WINDOWS)
            _Py_wgetcwd(fullpath, Py_ARRAY_LENGTH(fullpath));
            argv0 = fullpath;
            n = wcslen(argv0);
        #else
            argv0 = L".";
            n = 1;
        #endif
    }

And it defers the error handler to later. Example of Python 3 running in a removed directory:

$ python3
Python 3.7.2 (default, Jan 16 2019, 19:49:22) 
>>> import os
>>> os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory

>>> os.path.abspath('.')
Traceback (most recent call last):
  File "/usr/lib64/python3.7/posixpath.py", line 383, in abspath
    cwd = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory

I would prefer "." than "-m".
History
Date User Action Args
2019-03-18 12:06:48vstinnersetrecipients: + vstinner, ronaldoussoren, ncoghlan, ned.deily, lkollar, pablogsal
2019-03-18 12:06:48vstinnersetmessageid: <1552910808.49.0.865500869393.issue36236@roundup.psfhosted.org>
2019-03-18 12:06:48vstinnerlinkissue36236 messages
2019-03-18 12:06:48vstinnercreate