2 ms·
It's not. That sys.path includes "." when running a script lets you import files next to the script. This is trivial to confirm: > cat "import bar" > foo.p
by masklinn 6y ago
It's not. That sys.path includes "." when running a script lets you import files next to the script. This is trivial to confirm:
> cat "import bar" > foo.py
> touch bar.py
> python foo.py
> python -I foo.py
Traceback (most recent call last):
File "foo.py", line 1, in <module>
import bar
ModuleNotFoundError: No module named 'bar'
and this is exactly the feature which makes it risky to run `python` from an untrusted location.
- jwilk 6y agoBut there's no PYTHONPATH involved here. If you changed semantics of PYTONPATH as dwheeler suggested, everything would continue to work as you shown.