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

Nick Coghlan report at bugs.python.org
Fri Nov 25 01:46:34 CET 2011

New submission from Nick Coghlan <ncoghlan at gmail.com>:

PEP 395 spends a lot of time discussing ways that the current automatic initialisation of sys.path[0] can go wrong, and even the proposed improvements in that PEP don't claim to fix the default behaviour for every possible scenario (just many of the most common ones).

The unittest module gets around similar problems with test autodiscovery by providing an explicit "-t" (for 'toplevel') command line option.

While '-t' is not available for the main interpreter executable (and nor is '-d' for directory), '-p' for "path0" is a possibility.

Directory execution (for example) would then be equivalent to:

  python -p dirname dirname/__main__.py

A separate '--nopath0' option could also be provided to explicitly disable path initialisation based on the script being executed (see http://lists.debian.org/debian-python/2011/11/msg00058.html)

messages: 148295
nosy: ncoghlan
priority: normal
severity: normal
status: open
title: Add '-p'/'--path0' command line option to override sys.path[0] initialisation

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list