I have a python script that uses the __file__
variable to take some action. This was working fine before I used zipapp since __file__
matched the actual running file.
Now I am starting to use zipapp and the logic doesn't work anymore, because __file__
is "loinc.pyz"
and not "loinc.py"
.
Is there a way that, within my Python code, I can tell if the file is actually loinc.pyz, say, rather than loinc.py?
The only way I can see to do it now is to just try to see if __file__ + "z"
exists, and if it does, assume we're using zipapp. But I'd like something more elegant.
I looked at the specifications from zipapp https://docs.python.org/3/library/zipapp.html but couldn't find anything. Looked at the 8 pages of zipapp-referenced questions in Stack Overflow and nothing either.