Skip to content

Instantly share code, notes, and snippets.

@bukzor
Created September 14, 2020 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bukzor/21ea47b35ca6c4f36a211edc9b15be25 to your computer and use it in GitHub Desktop.
Save bukzor/21ea47b35ca6c4f36a211edc9b15be25 to your computer and use it in GitHub Desktop.
__file__ is always realpath?
$ 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