{"id":1024,"date":"2023-03-12T20:18:00","date_gmt":"2023-03-12T14:48:00","guid":{"rendered":"https:\/\/geekpython.in\/?p=1024"},"modified":"2023-08-15T13:52:57","modified_gmt":"2023-08-15T08:22:57","slug":"tempfile-in-python","status":"publish","type":"post","link":"https:\/\/geekpython.in\/tempfile-in-python","title":{"rendered":"How To Use tempfile To Create Temporary Files and Directories in Python"},"content":{"rendered":"\n<p>Python has a rich collection of standard libraries to carry out various tasks. In Python, there is a module called&nbsp;<strong>tempfile<\/strong>&nbsp;that allows us to create and manipulate temporary files and directories.<\/p>\n\n\n\n<p>We can use tempfile to create temporary files and directories for storing temporary data during the program execution. The module has functions that allow us to create, read, and manipulate temporary files and directories.<\/p>\n\n\n\n<p>In this article, we&#8217;ll go over the fundamentals of the tempfile module, including creating, reading, and manipulating temporary files and directories, as well as cleaning up after we&#8217;re done with them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-a-temporary-file\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-creating-temporary-file\"><\/a>Creating a temporary file using tempfile<\/h2>\n\n\n\n<p>The tempfile module includes a function called&nbsp;<code>TemporaryFile()<\/code>&nbsp;that allows us to create a temporary file for use as temporary storage. Simply enter the following code to create a temporary file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Creating a temporary file\ntemp_file = tempfile.TemporaryFile()\n\nprint(f'Tempfile object: {temp_file}')\nprint(f'Tempfile name: {temp_file.name}')\n\n# Closing the file \ntemp_file.close()<\/pre><\/div>\n\n\n\n<p>First, we imported the module, and because it is part of the standard Python library, we did not need to install it.<\/p>\n\n\n\n<p>Then we used the&nbsp;<code>TemporaryFile()<\/code>&nbsp;function to create a temporary file, which we saved in the&nbsp;<code>temp_file<\/code>&nbsp;variable. Then we added print statements to display the tempfile object and temporary file name.<\/p>\n\n\n\n<p>Finally, we used the&nbsp;<code>close()<\/code>&nbsp;function to close the file, just as we would any other file. This will automatically clean up and delete the file.<\/p>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Tempfile object: &lt;tempfile._TemporaryFileWrapper object at 0x0000015E54545AE0&gt;\nTempfile name: C:\\Users\\SACHIN\\AppData\\Local\\Temp\\tmp5jyjavv2<\/pre><\/div>\n\n\n\n<p>We got the location of the object in memory when we printed the object&nbsp;<code>temp_file<\/code>, and we got the random name&nbsp;<code>tmp5jyjavv2<\/code>&nbsp;with the entire path when we printed the name of the temporary file.<\/p>\n\n\n\n<p>We can specify&nbsp;<code>dir<\/code>&nbsp;parameter to create a temporary file in the specified directory.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Creating a temporary file in the cwd\nnamed_file = tempfile.TemporaryFile(\n    dir='.\/'\n)\n\nprint('File created in the cwd')\nprint(named_file.name)\n\n# Closing the file\nnamed_file.close()<\/pre><\/div>\n\n\n\n<p>The file will be created in the current working directory.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">File created in the cwd\nD:\\SACHIN\\Pycharm\\tempfile_module\\tmptbg9u6wk<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"writing-text-and-reading-it\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-writing-text-and-reading-it\"><\/a>Writing text and reading it<\/h2>\n\n\n\n<p>The&nbsp;<code>TemporaryFile()<\/code>&nbsp;function sets the mode parameter&nbsp;<code>'w+b'<\/code>&nbsp;to the default value to read and write files in a binary mode. We can also use&nbsp;<code>'w+t'<\/code>&nbsp;mode to write text data into the temporary file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Creating a temporary file\nfile = tempfile.TemporaryFile()\n\ntry:\n    # Writing into the temporary file\n    file.write(b\"Welcome to GeekPython.\")\n    # Position to start reading the file\n    file.seek(0)  # Reading will start from beginning\n    # Reading the file\n    data = file.read()\n    print(data)\nfinally:\n    # Closing the file\n    file.close()\n\n----------\nb'Welcome to GeekPython.'<\/pre><\/div>\n\n\n\n<p>In the above code, we created a temporary file and then used the&nbsp;<code>write()<\/code>&nbsp;function to write data into it, passing the string in bytes format (as indicated by the prefix&nbsp;<code>'b'<\/code>&nbsp;before the content).<\/p>\n\n\n\n<p>Then we used the&nbsp;<code>read()<\/code>&nbsp;function to read the content, but first, we specified the position from which to begin reading the content using the&nbsp;<code>seek(0)<\/code>&nbsp;(start from the beginning) function, and finally, we closed the file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"using-context-manager\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-using-context-manager\"><\/a>Using context manager<\/h2>\n\n\n\n<p>We can also create temporary files using the context managers such as&nbsp;<code>with<\/code>&nbsp;keyword. Also, the following example will show us how to write and read text data into the temporary file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Using with statement creating a temporary file\nwith tempfile.TemporaryFile(mode='w+t') as file:\n    # Writing text data into the file\n    file.write('Hello Geeks!')\n    # Specifying the position to start reading\n    file.seek(0)\n    # Reading the content\n    print(file.read())\n    # Closing the file\n    file.close()<\/pre><\/div>\n\n\n\n<p>In the above code, we used the&nbsp;<code>with<\/code>&nbsp;statement to create a temporary file and then opened it in text mode(<code>'w+t'<\/code>) and did everything the same as we do for handling other files in Python.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Hello Geeks!<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"named-temporary-file\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-named-temporary-file\"><\/a>Named temporary file<\/h2>\n\n\n\n<p>To take more control over making the temporary file like naming the temporary file as we want or keeping it or deleting it, then we can use&nbsp;<code>NamedTemporaryFile()<\/code>.<\/p>\n\n\n\n<p>When creating a temporary file, we can specify a&nbsp;<strong>suffix<\/strong>&nbsp;and a&nbsp;<strong>prefix<\/strong>, and we can choose whether to delete or keep the temporary file. It has a&nbsp;<code>delete<\/code>&nbsp;parameter that defaults to&nbsp;<code>True<\/code>, which means that the file will be deleted automatically when we close it, but we can change this value to&nbsp;<code>False<\/code>&nbsp;to keep it.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Creating a temporary file using NamedTemporaryFile()\nnamed_file = tempfile.NamedTemporaryFile()\n\nprint('Named file:', named_file)\nprint('Named file name:', named_file.name)\n\n# Closing the file\nnamed_file.close()\n\n----------\nNamed file: &lt;tempfile._TemporaryFileWrapper object at 0x000001E70CDEC310&gt;\nNamed file name: C:\\Users\\SACHIN\\AppData\\Local\\Temp\\tmpk6ycz_ek<\/pre><\/div>\n\n\n\n<p>The output of the above code is the same as when we created the temporary file using the&nbsp;<code>TemporaryFile()<\/code>&nbsp;function, it&#8217;s because&nbsp;<code>NamedTemporaryFile()<\/code>&nbsp;operates exactly as&nbsp;<code>TemporaryFile()<\/code>&nbsp;but the temporary file created using the&nbsp;<code>NamedTemporaryFile()<\/code>&nbsp;is guaranteed to have a visible name in the file system.<\/p>\n\n\n\n<p><strong>How to customize the name of a temporary file?<\/strong><\/p>\n\n\n\n<p>As you can see, the name of our temporary file is generated at random, but we can change that with the help of the&nbsp;<code>prefix<\/code>&nbsp;and&nbsp;<code>suffix<\/code>&nbsp;parameters.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Creating a temporary file using NamedTemporaryFile()\nnamed_file = tempfile.NamedTemporaryFile(\n    prefix='geek-',\n    suffix='-python'\n)\n\nprint('Named file name:', named_file.name)\n\n# Closing the file\nnamed_file.close()<\/pre><\/div>\n\n\n\n<p>The temporary file will now be created when the code is run, and its name will be prefixed and suffixed with the values we specified in the code above.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Named file name: C:\\Users\\SACHIN\\AppData\\Local\\Temp\\geek-n6luwuwx-python<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-temporary-directory\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-creating-temporary-directory\"><\/a>Creating temporary directory<\/h2>\n\n\n\n<p>To create a temporary directory, we can use&nbsp;<code>TemporaryDirectory()<\/code>&nbsp;function from the tempfile module.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Creating a temporary directory inside the TempDir\ntempdir = tempfile.TemporaryDirectory(\n    dir='TempDir'\n)\n\n# Printing the name of temporary dir\nprint('Temp Directory:', tempdir.name)\n\n# Cleaning up the dir\ntempdir.cleanup()<\/pre><\/div>\n\n\n\n<p>The above code will create a temporary directory inside the&nbsp;<strong><em>TempDir<\/em><\/strong>&nbsp;directory that we created in the root directory. Then we printed the name of the temporary directory and then called the&nbsp;<code>cleanup()<\/code>&nbsp;method to explicitly clean the temporary directory.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Temp Directory: TempDir\\tmplfu2ooew<\/pre><\/div>\n\n\n\n<p>We can use&nbsp;<code>with<\/code>&nbsp;statement to create a temporary directory and we can also specify&nbsp;<code>suffix<\/code>&nbsp;and&nbsp;<code>prefix<\/code>&nbsp;parameters.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">with tempfile.TemporaryDirectory(\n        dir='TempDir',\n        prefix='hey-',\n        suffix='-there'\n) as tempdir:\n    print(\"Temp Dir:\", tempdir)<\/pre><\/div>\n\n\n\n<p>When we create a temporary directory using the&nbsp;<code>with<\/code>&nbsp;statement the name of the directory will be assigned to the target of the&nbsp;<code>as<\/code>&nbsp;clause. To get the name of the temporary directory, we passed&nbsp;<code>tempdir<\/code>&nbsp;rather than&nbsp;<code>tempdir.name<\/code>&nbsp;in the print statement.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Temp Dir: TempDir\\hey-q14i1hc4-there<\/pre><\/div>\n\n\n\n<p>You will notice that this time we didn&#8217;t use the&nbsp;<code>cleanup()<\/code>&nbsp;method, that&#8217;s because the temporary directory and its content are removed after the completion of the context of the temporary directory object.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"spooled-temporary-file\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-spooledtemporaryfile\"><\/a>SpooledTemporaryFile<\/h2>\n\n\n\n<p>The&nbsp;<code>SpooledTemporaryFile()<\/code>&nbsp;function is identical to&nbsp;<code>TemporaryFile()<\/code>, with the exception that it stores the data in memory up until the maximum size is reached or&nbsp;<code>fileno()<\/code>&nbsp;method is called.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Creating a temporary file to spool data into it\nsp_file = tempfile.SpooledTemporaryFile(max_size=10)\nprint(sp_file)\n\n# Writing into the file\nsp_file.write(b'Hello from GeekPython')\n\n# Printing the size of the file\nprint(sp_file.__sizeof__())\n\n# Printing if data is written to the disk\nprint(sp_file._rolled)\nprint(sp_file._file)<\/pre><\/div>\n\n\n\n<p>With the&nbsp;<code>max_size<\/code>&nbsp;parameter set to&nbsp;<strong>10<\/strong>, we used the&nbsp;<code>SpooledTemporaryFile()<\/code>&nbsp;function to create a spooled temporary file. It indicates that file size up to 10 can be stored in the memory before it is rolled over to the on-disk file.<\/p>\n\n\n\n<p>Then we wrote some data into the file and printed the size of the file using the&nbsp;<code>__sizeof__<\/code>&nbsp;attribute.<\/p>\n\n\n\n<p>There is a&nbsp;<code>rollover()<\/code>&nbsp;method by which we can see whether the data is in the memory or rolled over to the on-disk temporary file. This method returns a boolean value,&nbsp;<strong>True<\/strong>&nbsp;means the data is rolled over and&nbsp;<strong>False<\/strong>&nbsp;means the data is still in the memory of the spooled temporary file.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">&lt;tempfile.SpooledTemporaryFile object at 0x0000023FFBD0C370&gt;\n32\nTrue\n&lt;tempfile._TemporaryFileWrapper object at 0x0000023FFBD0D930&gt;<\/pre><\/div>\n\n\n\n<p>The temporary file object is&nbsp;<strong>SpooledTemporaryFile<\/strong>, as can be seen. Because the amount of data we wrote into the file exceeded the allowed size, the data was rolled over, and we received the boolean value&nbsp;<code>True<\/code>.<\/p>\n\n\n\n<p>Depending on the mode we specified, this function returns a file-like object whose&nbsp;<code>_file<\/code>&nbsp;attribute is either an&nbsp;<code>io.BytesIO<\/code>&nbsp;or an&nbsp;<code>io.TextIOWrapper<\/code>&nbsp;(binary or text). Up until the data exceeded the max size, this function holds the data in memory using the&nbsp;<code>io.BytesIO<\/code>&nbsp;or&nbsp;<code>io.TextIOWrapper<\/code>&nbsp;buffer.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\nwith tempfile.SpooledTemporaryFile(mode=\"w+t\", max_size=50) as sp_file:\n    print(sp_file)\n\n    # Running a while loop until the data gets rolled over\n    while sp_file._rolled == False:\n        sp_file.write(\"Welcome to GeekPython\")\n        print(sp_file._rolled, sp_file._file)<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">&lt;tempfile.SpooledTemporaryFile object at 0x000001A8901CC370&gt;\nFalse &lt;_io.TextIOWrapper encoding='cp1252'&gt;\nFalse &lt;_io.TextIOWrapper encoding='cp1252'&gt;\nTrue &lt;tempfile._TemporaryFileWrapper object at 0x000001A8906388E0&gt;<\/pre><\/div>\n\n\n\n<p>Until the data is rolled over, we ran a&nbsp;<code>while<\/code>&nbsp;loop and printed the&nbsp;<code>_file<\/code>&nbsp;attribute of the&nbsp;<code>SpooledTemporaryFile<\/code>&nbsp;object. As we can see the data was stored in the memory using the&nbsp;<code>io.TextIOWrapper<\/code>&nbsp;buffer(mode was set to text) and when the data was rolled over, the code returned the temporary file object.<\/p>\n\n\n\n<p><strong>We can do the same with data in binary format.<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\nwith tempfile.SpooledTemporaryFile(mode=\"w+b\", max_size=50) as sp_file:\n    print(sp_file)\n\n    # Running a while loop until the data gets rolled over\n    while sp_file._rolled == False:\n        sp_file.write(b\"Welcome to GeekPython\")\n        print(sp_file._rolled, sp_file._file)<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">&lt;tempfile.SpooledTemporaryFile object at 0x00000223C633C370&gt;\nFalse &lt;_io.BytesIO object at 0x00000223C6331580&gt;\nFalse &lt;_io.BytesIO object at 0x00000223C6331580&gt;\nTrue &lt;tempfile._TemporaryFileWrapper object at 0x00000223C67A8850&gt;<\/pre><\/div>\n\n\n\n<p>We can also call&nbsp;<code>fileno()<\/code>&nbsp;to roll over the file content.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\nwith tempfile.SpooledTemporaryFile(mode=\"w+b\", max_size=500) as sp_file:\n    print(sp_file)\n\n    for _ in range(3):\n        sp_file.write(b'Hey, there welcome')\n        print(sp_file._rolled, sp_file._file)\n\n    print('Data is written to the disk before reaching the max size.')\n    # Calling the fileno() method\n    sp_file.fileno()\n    print(sp_file._rolled, sp_file._file)<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">&lt;tempfile.SpooledTemporaryFile object at 0x000001F51D12C370&gt;\nFalse &lt;_io.BytesIO object at 0x000001F51D121580&gt;\nFalse &lt;_io.BytesIO object at 0x000001F51D121580&gt;\nFalse &lt;_io.BytesIO object at 0x000001F51D121580&gt;\nData is written to the disk before reaching the max size.\nTrue &lt;tempfile._TemporaryFileWrapper object at 0x000001F51D5A0970&gt;<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"low-level-functions\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-low-level-functions\"><\/a>Low-level functions<\/h2>\n\n\n\n<p>There are some low-level functions included in the tempfile module. We&#8217;ll explore them one by one.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mkstemp-and-mkdtemp\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-mkstemp-and-mkdtemp\"><\/a>mkstemp and mkdtemp<\/h3>\n\n\n\n<p><code>mkstemp<\/code>&nbsp;is used for creating a temporary file in the most secure manner possible and&nbsp;<code>mkdtemp<\/code>&nbsp;is used to create a temporary directory in the most secure manner possible.<\/p>\n\n\n\n<p>They also have parameters like&nbsp;<code>suffix<\/code>,&nbsp;<code>prefix<\/code>&nbsp;and&nbsp;<code>dir<\/code>&nbsp;but&nbsp;<code>mkstemp<\/code>&nbsp;has one additional&nbsp;<code>text<\/code>&nbsp;parameter which defaults to&nbsp;<code>False<\/code>(binary mode), if we make it&nbsp;<code>True<\/code>&nbsp;then the file will be opened in text mode.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\n# Using mkstemp\nfile = tempfile.mkstemp(prefix='hello-', suffix='-world')\nprint('Created File:', file)\n\n# Using mkdtemp\ndirectory = tempfile.mkdtemp(dir='TempDir')\nprint('Directory Created:', directory)\n\n----------\nCreated File: (3, 'C:\\\\Users\\\\SACHIN\\\\AppData\\\\Local\\\\Temp\\\\hello-xmtqn88f-world')\nDirectory Created: TempDir\\tmp_6coyqq2<\/pre><\/div>\n\n\n\n<p><strong>Note<\/strong>: There is a function called&nbsp;<code>mktemp()<\/code>&nbsp;also which is deprecated.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"gettempdir-and-gettempdirb\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-gettempdir-and-gettempdirb\"><\/a><strong>gettempdir<\/strong>&nbsp;and&nbsp;<strong>gettempdirb<\/strong><\/h3>\n\n\n\n<p><code>gettempdir()<\/code>&nbsp;is used to return the name of the directory used for temporary files and&nbsp;<code>gettempdirb()<\/code>&nbsp;also return the name of the directory but in bytes.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">import tempfile\n\nprint(tempfile.gettempdir())\nprint(tempfile.gettempdirb())\n\n----------\nC:\\Users\\SACHIN\\AppData\\Local\\Temp\nb'C:\\\\Users\\\\SACHIN\\\\AppData\\\\Local\\\\Temp'<\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"conclusion\"><a href=\"https:\/\/geekpython.in\/tempfile-in-python#heading-conclusion\"><\/a>Conclusion<\/h1>\n\n\n\n<p>The&nbsp;<strong>tempfile<\/strong>&nbsp;module, which offers functions to create temporary files and directories, was covered in this article. We have used various functions from the tempfile module in code examples, which has helped us better understand how these functions operate.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83c\udfc6<strong>Other articles you might be interested in if you liked this one<\/strong><\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/match-case-in-python\" rel=\"noreferrer noopener\">Use match case statement for pattern matching in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/class-inheritance-in-python\" rel=\"noreferrer noopener\">Types of class inheritance in Python with examples<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/f-string-in-python\" rel=\"noreferrer noopener\">An improved and modern way of string formatting in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/integrate-postgresql-database-in-python\" rel=\"noreferrer noopener\">Integrate PostgreSQL database with Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/argmax-function-in-numpy-and-tensorflow\" rel=\"noreferrer noopener\">Argmax function in NumPy and TensorFlow &#8211; Are they the same<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/multiple-inputs-in-python\" rel=\"noreferrer noopener\">Take multiple inputs from the user in a single line in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code\" rel=\"noreferrer noopener\">Perform a parallel iteration over multiple iterables using zip() function in Python<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>That&#8217;s all for now<\/strong><\/p>\n\n\n\n<p><strong>Keep Coding\u270c\u270c<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python has a rich collection of standard libraries to carry out various tasks. In Python, there is a module called&nbsp;tempfile&nbsp;that allows us to create and manipulate temporary files and directories. We can use tempfile to create temporary files and directories for storing temporary data during the program execution. The module has functions that allow us [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1026,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[2,42],"tags":[43,12,31],"class_list":["post-1024","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-modules","tag-modules","tag-python","tag-python3","entry","has-media"],"_links":{"self":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/comments?post=1024"}],"version-history":[{"count":5,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1024\/revisions"}],"predecessor-version":[{"id":1310,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/1024\/revisions\/1310"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media\/1026"}],"wp:attachment":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media?parent=1024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/categories?post=1024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/tags?post=1024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}