J
Jonathan Wright
import tempfile
import types
print isinstance(tempfile.TemporaryFile(), types.FileType)
Prints False on Windows and True on linux or any other posix system.
The reason for the difference is on posix systems TemporaryFile returns
an actual file (the result of os.fdopen()) and on windows,
TemporaryFile returns a file wrapper which forwards getattr calls to
the underlying file.
The wrapper used on windows provides an alternative close method that
deletes the temporary file.
Should the wrapper inherit types.FileType?
Jonathan.
import types
print isinstance(tempfile.TemporaryFile(), types.FileType)
Prints False on Windows and True on linux or any other posix system.
The reason for the difference is on posix systems TemporaryFile returns
an actual file (the result of os.fdopen()) and on windows,
TemporaryFile returns a file wrapper which forwards getattr calls to
the underlying file.
The wrapper used on windows provides an alternative close method that
deletes the temporary file.
Should the wrapper inherit types.FileType?
Jonathan.