Created
July 17, 2023 04:30
-
-
Save wonderbeyond/6dcf8bcfe2671ef72c36cf2ff75e3307 to your computer and use it in GitHub Desktop.
An alternative to tempfile.NamedTemporaryFile working with Windows NT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from contextlib import contextmanager | |
from tempfile import mkstemp | |
@contextmanager | |
def MakeTemporaryFile(suffix=None, prefix=None, dir=None): | |
"""An alternative to tempfile.NamedTemporaryFile working with Windows NT.""" | |
try: | |
fd, name = mkstemp(suffix=suffix, prefix=prefix, dir=dir) | |
yield name | |
finally: | |
os.close(fd) | |
os.remove(name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment