This function creates a temporary directory. This file too is deleted immediately upon closing it. The name can be retrieved by name attribute of file object. The only difference is that a file with a random filename is visible in the designated temp folder of operating system. This function is similar to TemporaryFile() function. > ff = tempfile.TemporaryFile(mode = 'w+') > f.write(b'Welcome to TutorialsPoint')įollowing example opens TemporaryFile object in w+ mode to write and then read text data instead of binary data. Following code shows usage of TemporaryFile() function. What is important, the file’s entry in temp folder is removed as soon as the file object is closed. The file is opened in wb+ mode by default, which means it can be simultaneously used to read/write binary data in it. This function creates a temporary file in the temp directory and returns a file object, similar to built-in open() function. For example, under Windows the temp folder resides in profile/AppData/Local/Temp while in linux the temporary files are held in /tmp directory.įollowing functions are defined in tempfile module TemporaryFile() They are created in special temp directories that are defined by operating system file systems. The tempfile module in standard library defines functions for creating temporary files and directories.
0 Comments
Leave a Reply. |