Created
September 14, 2020 20:02
-
-
Save bukzor/21ea47b35ca6c4f36a211edc9b15be25 to your computer and use it in GitHub Desktop.
__file__ is always realpath?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd "$(mktemp -d)" | |
$ ln -sf realpath symlink | |
$ mkdir realpath | |
$ cd symlink | |
$ touch foo.py | |
$ python3.6 -m compileall $PWD/foo.py | |
Compiling '/tmp/tmp.Y45AhTTLrt/symlink/foo.py'... | |
# Note: "/symlink/" in the path | |
$ strings __pycache__/foo.cpython-36.pyc | |
P/tmp/tmp.Y45AhTTLrt/symlink/foo.py | |
<module> | |
# Note: "/symlink/" not in the path | |
$ python3.6 -c 'import foo; print(foo.__file__, foo.__cached__, sep="\n")' | |
/tmp/tmp.Y45AhTTLrt/realpath/foo.py | |
/tmp/tmp.Y45AhTTLrt/realpath/__pycache__/foo.cpython-36.pyc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment