[New-bugs-announce] [issue34444] Module's __file__ should be absolute always ("." in sys.path)
daniel hahler
report at bugs.python.org
Mon Aug 20 12:57:16 EDT 2018
New submission from daniel hahler <python-bugs at thequod.de>:
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 before chdir already causes failure.
import imported
os.chdir('/')
print(imported.__file__) # ./imported.py
assert imported.__file__ == os.path.abspath(imported.__file__)
```
It works for "" in sys.path (https://bugs.python.org/issue18416).
----------
components: Interpreter Core
messages: 323800
nosy: blueyed
priority: normal
severity: normal
status: open
title: Module's __file__ should be absolute always ("." in sys.path)
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34444>
_______________________________________
More information about the New-bugs-announce
mailing list