3 ms·
> Why is a relative path in the PYTHONPATH necessarily bad practice? It's not a rhetorical question, I am genuinely curious. Among other things, what happens i
by JoshTriplett 11y ago
> Why is a relative path in the PYTHONPATH necessarily bad practice? It's not a rhetorical question, I am genuinely curious.
Among other things, what happens if your Python code changes its working directory, then subsequently tries to import a module? Consequences range from "doesn't work" to "introduces a security vulnerability by running arbitrary Python code from an untrusted directory".
- ehremo 11y agoActually I don't believe that would happen. I think the relative PYTHONPATH gets expanded at startup and becomes an absolute path. Subsequent changes to the working directory wouldn't affect it.
- pyre 11y agoThat seems correct: /tmp $ PYTHONPATH='./test' /usr/bin/python -c 'import sys; print sys.path[:3]' ['', '/private/tmp/test', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip']
- JoshTriplett 11y agoGood to know, thanks. It's still odd for software to only work when launched from a specific directory, but not necessarily a critical security vulnerability then.