[issue13475] Add '-p'/'--path0' command line option to override sys.path[0] initialisation

Eric Snow report at bugs.python.org
Sun May 27 00:20:32 CEST 2012


Eric Snow <ericsnowcurrently at gmail.com> added the comment:

> Before this is assigned a short option form, I would like to ask
> whether anybody but experts will be able to make a proper use of this
> option.

Do you mean relative to a long form?  And what would constitute improper use for the option?

As Nick noted earlier in this issue, the implicit setting of sys.path[0] is a convenience for some cases, and I can appreciate that.  My complaint is that it is not an obvious behavior.  Furthermore, in an import system that has eliminated implicit relative imports it can lead to confusing behavior.  I consider Nick's proposal the best solution given the constraints we have.

If people do not use it, the status quo is unaffected.  If they do use it, they will be explicitly affecting sys.path[0].  If they use it without knowing what it's for, it will at worst cause imports to happen from unexpected sources (or not happen at all).  To me this doesn't seem that different from the way things are now when someone doesn't understand about sys.path[0] initialization.

> (I also don't understand what it adds over PYTHONPATH)

It provides an explicit alternative to the default implicit insertion to sys.path[0].  If the default behavior were no implicit initialization, then I'd agree that PYTHONPATH is sufficient.

> As for the patch, it lacks error checking when calling C API
> functions.

Ah, yes.  Spaced it.  Patch updated (and warnings fixed).

This brings me to ask what the behavior should be when we have errors come back from those C API functions?  In the patch I just have it fall back to the default sys.path[0] behavior.  However, wouldn't an error indicate a deeper problem?  If so, shouldn't Py_FatalError() be called?

----------
Added file: http://bugs.python.org/file25730/issue13475_2.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13475>
_______________________________________


More information about the Python-bugs-list mailing list