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 Michel Desmoulin, ammar2, ncoghlan, r.david.murray, vstinner, xtreak, yselivanov
Date 2019-10-21.21:44:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I understand that the discussion is about my commit 3939c321c90283b49eddde762656e4b1940e7150 which changed multiple things:
  Python now gets the absolute path of the script filename specified on
  the command line (ex: ``python3``): the ``__file__`` attribute of
  the ``__main__`` module, ``sys.argv[0]`` and ``sys.path[0]`` become an
  absolute path, rather than a relative path.

I understand that the complain is not about sys.modules['__main__'].__file__ nor sys.path[0], but only sys.argv[0].

The sys.argv documentation says:

"The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not)."

I understand that before my change, sys.argv[0] was sometimes relative, and sometimes absolute. With my change, sys.argv[0] should now always be asolute.

There are cases where an absolute path is preferred. There are cases where a relative path is preferred. I'm trying to understand the scope of the issue.


I don't know this code. It seems like sys.argv[0] is used to lookup in a dict, and that dict keys are supposed to be "module names". I don't understand in which cases sys.argv[0] could be a module *name*, since sys.argv[0] seems like a relative or absolute path.


The code starts by sys.argv.pop(0): remove sys.argv[0].


if sys.argv[0].startswith('pyperun'): ...

I understand that my change broke such test. Did this test work before my change when specifying the absolute path to run the script? Like path/to/ rather than Such code looks fragile: using os.path.basename() would be safer here.


  home = os.path.expanduser("~")
  svnWorkingCopiesPath = os.path.join(home, "svnwork")
  gitReposPath = os.path.join(home, "gitrepos")
  if sys.argv[0].startswith(svnWorkingCopiesPath) 
     or sys.argv[0].startswith(gitReposPath): ...

On my Linux, os.path.expanduser("~") is an absolute path and so svnWorkingCopiesPath and gitReposPath should be absolute paths, no?

My change made this code more reliable, rather than breaking it, no?
Date User Action Args
2019-10-21 21:44:31vstinnersetrecipients: + vstinner, ncoghlan, r.david.murray, yselivanov, Michel Desmoulin, ammar2, xtreak
2019-10-21 21:44:31vstinnersetmessageid: <>
2019-10-21 21:44:31vstinnerlinkissue20443 messages
2019-10-21 21:44:31vstinnercreate