Author ncoghlan
Recipients ncoghlan
Date 2011-11-25.00:46:33
SpamBayes Score 2.27803e-07
Marked as misclassified No
Message-id <>
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/

A separate '--nopath0' option could also be provided to explicitly disable path initialisation based on the script being executed (see
Date User Action Args
2011-11-25 00:46:34ncoghlansetrecipients: + ncoghlan
2011-11-25 00:46:34ncoghlansetmessageid: <>
2011-11-25 00:46:33ncoghlanlinkissue13475 messages
2011-11-25 00:46:33ncoghlancreate