Message346789
Example of case where a module path is still relative:
---
import sys
import os
modname = 'relpath'
filename = modname + '.py'
sys.path.insert(0, os.curdir)
with open(filename, "w") as fp:
print("import sys", file=fp)
print("mod = sys.modules[__name__]", file=fp)
print("print(f'{__file__=}')", file=fp)
print("print(f'{mod.__file__=}')", file=fp)
print("print(f'{mod.__cached__=}')", file=fp)
__import__(modname)
os.unlink(filename)
---
Output:
---
__file__='./relpath.py'
mod.__file__='./relpath.py'
mod.__cached__='./__pycache__/relpath.cpython-39.pyc'
---
__file__ and mod.__file__ are relative paths: not absolute paths. |
|
Date |
User |
Action |
Args |
2019-06-28 00:18:23 | vstinner | set | recipients:
+ vstinner, ncoghlan, r.david.murray, yselivanov |
2019-06-28 00:18:23 | vstinner | set | messageid: <1561681103.33.0.105079209119.issue20443@roundup.psfhosted.org> |
2019-06-28 00:18:23 | vstinner | link | issue20443 messages |
2019-06-28 00:18:23 | vstinner | create | |
|