Author ncoghlan
Recipients ncoghlan
Date 2011-11-25.00:46:33
SpamBayes Score 2.27803e-07
Marked as misclassified No
Message-id <1322181994.22.0.955887054946.issue13475@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2011-11-25 00:46:34ncoghlansetrecipients: + ncoghlan
2011-11-25 00:46:34ncoghlansetmessageid: <1322181994.22.0.955887054946.issue13475@psf.upfronthosting.co.za>
2011-11-25 00:46:33ncoghlanlinkissue13475 messages
2011-11-25 00:46:33ncoghlancreate