Brett Cannon added the comment:
RE: "This could be done when inserting something into `sys.path` maybe then
only?" That would require a custom object instead of a standard list for
sys.path which could detect insertion and then do the automatic absolute path
resolution which as you pointed
daniel hahler added the comment:
> And changing this to have to check every time import runs if an entry in
> sys.path is absolute would be costly (that's not a insignificant number of
> stat calls which we always try to avoid during import when possible).
This could be done when inserting
Brett Cannon added the comment:
So if you were to insert '.' via PYTHONPATH it would be made absolute as the
site module makes all entries in sys.path absolute during startup.
And changing this to have to check every time import runs if an entry in
sys.path is absolute would be costly
Batuhan added the comment:
I am not sure about computing absolute path every time when `__file__` called.
I guess it is a static thing, that get setted on the import time and never
changes. What you are proposing is to compute it dynamically which IMHO isn't
the best way.
--
nosy:
New submission from daniel hahler :
With "." in sys.path the "__file__" attribute will be a relative path, and
therefore cannot be used after "chdir".
This likely affects relative paths in general, but have not tested it.
```
import os
import sys
sys.path.insert(0, '.')
# Importing it