STINNER Victor <vstin...@redhat.com> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue20443> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com