So the code I'm working with unstores a sample file from a zip like that:
with ZipFile('spam.zip') as myzip:
myfile = myzip.open('eggs.txt')
return myfile # <class 'zipfile.ZipExtFile(io.BufferedIOBase)'>
I need to work with FileResponse
which expects a path to a file.
So when checking how to retrieve the path of an opened file in Python the solutions seems to be (according to Get path from open file in Python):
myfile.name
But unfortunately this doesn't work with ZipExtFile
. It just returns the files' name instead of a path to where this unpacked file is stored.
How can I get the path from myfile
?
Or is there another way to get the file and it's path without changing the original zip file?