Is there a way to get the absolute path of a tempfile.TemporaryFile? The name attribute returns integer which seems to be the file descriptor, but would like to get the actual path name.
import tempfile
file = tempfile.TemporaryFile(mode="w", encoding="utf-8")
print(file.name)
-----
56
Looking for a way to get a similar result as below.
file = tempfile.NamedTemporaryFile(mode="w", encoding="utf-8")
print(file.name)
-----
/tmp/tmp6ran0e71
From the documentation for tempfile.TemporaryFile:
Emphasis on "Under Unix, the directory entry for the file is either not created at all or is removed immediately after the file is created", seeing that you are apparently under a Unix system,
tempfile.TemporaryFilewill not create or will not maintain a directory entry for the file. This is not the same under some other platforms though (e.g. Windows), where there will be a path even for atempfile.TemporaryFile(also explained in the docs).