[Python-ideas] sys.path is a hack - bringing it back under control
techtonik at gmail.com
Mon Feb 20 10:47:17 CET 2012
I often find this in my scripts/projects, that I run directly from checkout:
DEVPATH = os.path.dirname(os.path.abspath(__file__))
This seems like a hack to me, because the process of sys.path modification
is completely out of control for Python application developer, which means
it is easy to break an application and get lost. I don't remember the exact
user story for that bad association with sys.path (perhaps Django issue
#1908), but something makes me feel that I am not alone:
What I'd like to propose is some control/info over what modified sys.path.
The simplest case:
1. make sys.path a list of pairs (path, file-that-added-the-path)
2. make sys.path read-only
3. add sys.path.add() method for modification
4. logger for sys.path.add() events (or recipe how to implement it in
This will help a lot.
Limiting sys.path may cause a loss of some functionality if you need to
remove some or replace it completely, but I don't know where the ability to
reset() sys.path can be useful.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas