{"id":2905,"date":"2020-02-22T17:24:33","date_gmt":"2020-02-22T11:54:33","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=2905"},"modified":"2021-06-27T09:12:22","modified_gmt":"2021-06-27T03:42:22","slug":"python-delete-file","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-delete-file\/","title":{"rendered":"[Best] Ways to Delete a File in Python"},"content":{"rendered":"\n<p>Many times a user or a python programmer needs to delete a file. The reason maybe he\/she created the file by mistake, or there is no need for that file anymore. Whatever the reason, there are ways to <strong>Python Delete file<\/strong> without manually finding the file and deleting them by UI.<\/p>\n\n\n\n<p>There are multiple ways to Delete a File in Python but the best ways are the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>os.remove()<\/strong>&nbsp;removes a file.<\/li><li><strong>os.unlink()<\/strong> removes a file.  it is a Unix name of remove() method.<\/li><li><strong>shutil.rmtree()<\/strong> deletes a directory and all its contents.<\/li><li><strong>pathlib.Path.unlink()<\/strong> deletes a single file  The <strong>pathlib<\/strong> module is available in Python 3.4 and above.<\/li><\/ul>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Python_Delete_File_Using_osremove\" >Python Delete File Using os.remove()<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Syntax\" >Syntax:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Parameters\" >Parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Return_Value\" >Return Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Example_1_Basic_Example_to_Remove_a_File_Using_osremove_Method\" >Example 1: Basic Example to Remove a File Using os.remove() Method.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Example_2_Checking_if_File_Exists_using_ospathisfile_and_Deleting_it_With_osremove\" >Example 2: Checking if File Exists using&nbsp;os.path.isfile and Deleting it With os.remove<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Example_3_Python_Program_to_Delete_all_files_with_a_specific_extension\" >Example 3: Python Program to Delete all files with a specific extension<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Example_4_Python_Program_to_Delete_All_Files_Inside_a_Folder\" >Example 4: Python Program to Delete All Files Inside a Folder<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Python_Delete_File_Using_osunlink\" >Python Delete File Using os.unlink()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Python_Delete_File_Using_shutilrmtree\" >Python Delete File Using shutil.rmtree()<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Syntax-2\" >Syntax:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Parameters-2\" >Parameters:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Example_Python_Program_to_Delete_a_File_Using_shutilrmtree\" >Example: Python Program to Delete a File Using shutil.rmtree()<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Python_Delete_File_Using_pathlibPathunlink\" >Python Delete File Using pathlib.Path.unlink()<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Example_Python_Program_to_Delete_a_File_Using_pathlib\" >Example: Python Program to Delete a File Using pathlib<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Using_pathlibPathrmdir_to_remove_Empty_Directory\" >Using pathlib.Path.rmdir() to remove Empty Directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#References_and_Must_Read\" >References and Must Read<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-python-delete-file-using-os-remove\"><span class=\"ez-toc-section\" id=\"Python_Delete_File_Using_osremove\"><\/span>Python Delete File Using os.remove()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>OS module<\/strong>&nbsp;in Python provides functions for interacting with the operating system. OS comes under Python\u2019s standard utility modules. This module provides a portable way of using operating system dependent functionality.<\/p>\n\n\n\n<p><strong>os.remove()<\/strong> method in Python is used to remove or delete a file path. This method can not <strong>remove or delete a directory<\/strong>. If the specified path is a directory then&nbsp;<strong>OSError<\/strong>&nbsp;will be raised by the method.&nbsp;<\/p>\n\n\n\n<p>Note: You can use <code><strong style=\"font-style: italic;\">os.rmdir()<\/strong><\/code>&nbsp;can be used to remove the directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-syntax\"><span class=\"ez-toc-section\" id=\"Syntax\"><\/span>Syntax:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Following is the syntax for&nbsp;<strong>remove()<\/strong>&nbsp;method to delete a Python file \u2212<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.remove(path)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-parameters\"><span class=\"ez-toc-section\" id=\"Parameters\"><\/span>Parameters<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>path<\/strong>&nbsp;\u2212 This is the path or file name, which is to be removed.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-return-value\"><span class=\"ez-toc-section\" id=\"Return_Value\"><\/span>Return Value<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The <strong>remove()<\/strong> method doesn&#8217;t return value.<\/p>\n\n\n\n<p><strong><em>Let&#8217;s check out some of the examples to Delete Python File using os.remove function.<\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-1-basic-example-to-remove-a-file-using-os-remove-method\"><span class=\"ez-toc-section\" id=\"Example_1_Basic_Example_to_Remove_a_File_Using_osremove_Method\"><\/span>Example 1: Basic Example to Remove a File Using os.remove() Method.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Importing the os library\nimport os\n\n# Inbuilt function to remove files\nos.remove(\"test_file.txt\")\nprint(\"File removed successfully\")<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>File removed successfully<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong> In the above example we have deleted the file or removed the path of the file named <em>testfile.txt.<\/em> Steps Explaining how the program flow goes are:<br>1. First, we have imported the os library because the remove() method is present inside the os library.<br>2. Then we have used the inbuilt function os.remove() to delete the path of the file.<br>3. In this example, our sample file is &#8220;test_file.txt&#8221;. You can place your desired file here.<\/p>\n\n\n\n<p>Note: If there is no file named <em>test_file.txt<\/em> the above example will throw an error. So it&#8217;s better to check first whether the file is available or not before deleting the file. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-2-checking-if-file-exists-using-os-path-isfile-and-deleting-it-with-os-remove\"><span class=\"ez-toc-section\" id=\"Example_2_Checking_if_File_Exists_using_ospathisfile_and_Deleting_it_With_osremove\"><\/span>Example 2: <strong>Checking if File Exists using&nbsp;os.path.isfile and Deleting it With os.remove<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In example 1, we have just deleted the file present in the directory. The <strong><strong>os.remove()&nbsp;<\/strong><\/strong>method will search the file to remove in the working directory. So it&#8217;s always better to check if the file is there or not.<\/p>\n\n\n\n<p>Let&#8217;s learn how to check if the file with that name available in that path or not. We are using <strong>os.path.isfile <\/strong>to check the availability of file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#importing the os Library\nimport os\n\n#checking if file exist or not\nif(os.path.isfile(\"test.txt\")):\n    \n    #os.remove() function to remove the file\n    os.remove(\"test.txt\")\n    \n    #Printing the confirmation message of deletion\n    print(\"File Deleted successfully\")\nelse:\nprint(\"File does not exist\")\n#Showing the message instead of throwig an error\n\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>File Deleted successfully<\/code><\/pre>\n\n\n\n<p>In the above example, we just added os.pasth.isfile() method. This method helps us to find out whether the file exists or not at a particular location.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-3-python-program-to-delete-all-files-with-a-specific-extension\"><span class=\"ez-toc-section\" id=\"Example_3_Python_Program_to_Delete_all_files_with_a_specific_extension\"><\/span>Example 3: Python Program to Delete all files with a specific extension<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import os \nfrom os import listdir\nmy_path = 'C:\\Python Pool\\Test\\'\n\nfor file_name in listdir(my_path):\n    \n    if file_name.endswith('.txt'):\n      \n        os.remove(my_path + file_name)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>Using this program, we will remove all files from the folder with&nbsp;the <em>.txt<\/em>&nbsp;extension.<\/p>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Import&nbsp;<em>os&nbsp;<\/em>module and&nbsp;<em>listdir&nbsp;<\/em>from the&nbsp;<em>os&nbsp;<\/em>module.&nbsp;<em>listdir&nbsp;<\/em>is required to get the list of all files in a specific folder and&nbsp;<em>os&nbsp;<\/em>module is required to remove a file.<\/li><li><em>my_path&nbsp;<\/em>is the path of the folder with all files.<\/li><li>We are <a href=\"http:\/\/www.pythonpool.com\/python-loop-through-files-in-directory\/\" target=\"_blank\" rel=\"noopener\">looping through the files<\/a> in the given folder.&nbsp;<em>listdir&nbsp;<\/em>is used to get one list of all files in a specific folder.<\/li><li><em>endswith&nbsp;<\/em>is used to check if a file ends with a<em>&nbsp;.txt<\/em>&nbsp;extension or not. As we are deleting all&nbsp;<em>.txt<\/em>&nbsp;files in a folder, this<em>&nbsp;if the condition<\/em>&nbsp;will verify this.<\/li><li>If the file name is ending with&nbsp;<em>.txt<\/em>&nbsp;extension, we are removing that file using&nbsp;<em>os.remove()<\/em>&nbsp;function. This function takes the&nbsp;<em>path of the file<\/em>&nbsp;as a parameter.&nbsp;<em>my_path + file_name<\/em>&nbsp;is the complete path for the file we are deleting.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-4-python-program-to-delete-all-files-inside-a-folder\"><span class=\"ez-toc-section\" id=\"Example_4_Python_Program_to_Delete_All_Files_Inside_a_Folder\"><\/span>Example 4: Python Program to Delete All Files Inside a Folder<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>To delete all files inside a particular directory, you simply have to use the&nbsp;<code>*<\/code>&nbsp;symbol as the pattern string.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Importing os and glob modules\nimport os, glob\n\n#Loop Through the folder projects all files and deleting them one by one\nfor file in glob.glob(\"pythonpool\/*\"):\n    os.remove(file)\n    print(\"Deleted \" + str(file))<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Deleted pythonpool\\test1.txt\nDeleted pythonpool\\test2.txt\nDeleted pythonpool\\test3.txt\nDeleted pythonpool\\test4.txt<\/code><\/pre>\n\n\n\n<p>In this example, we\u2019re deleting all the files inside the folder <strong>pythonpool<\/strong>.<\/p>\n\n\n\n<p>Note: If the folder will contain any sub-folder, then the error may be raised as the&nbsp;<code>glob.glob()<\/code>&nbsp;method fetches the names of all the folder contents, whether they\u2019re files or sub-folders. Therefore try to make the pattern more specific such as&nbsp;<code>*.*<\/code>&nbsp;to fetch only the contents that have an extension. <\/p>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-python-delete-file-using-os-unlink\"><span class=\"ez-toc-section\" id=\"Python_Delete_File_Using_osunlink\"><\/span>Python Delete File Using os.unlink()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>os.unlink<\/strong>() is an alias or another name of <strong>os.remove()<\/strong> . As in the Unix OS remove is also known as unlink.<\/p>\n\n\n\n<p><strong>Note:<\/strong> All the functionalities and syntax is the same of os.unlink() and os.remove(). Both of them are used to delete the Python file path.<br>Both are methods in the&nbsp;<em>os<\/em>&nbsp;module in Python\u2019s standard libraries which performs the deletion function. <\/p>\n\n\n\n<p>It has two names, aliases:&nbsp;<strong><em>os.unlink()<\/em><\/strong>&nbsp;and&nbsp;<strong><em>os.remove()<\/em><\/strong><\/p>\n\n\n\n<p>The likely reason for providing both aliases to the same function is that the maintainers of this module considered it likely that many programmers would be coming up to Python from lower-level programming in C, where the library function and underlying system call is named&nbsp;<em>unlink()&nbsp;<\/em>while others would, likely, be coming down to the language from using the shell or scripting where the command is&nbsp;<em>rm&nbsp;<\/em>(short for \u201cremove\u201d).<\/p>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-python-delete-file-using-shutil-rmtree\"><span class=\"ez-toc-section\" id=\"Python_Delete_File_Using_shutilrmtree\"><\/span>Python Delete File Using shutil.rmtree()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>shutil.rmtree():<\/strong>&nbsp;Removes the specified directory, all subdirectories, and all files. This function is especially dangerous because it removes everything without checking (Python assumes that you know what you\u2019re doing). As a result, you can easily lose data using this function.<\/p>\n\n\n\n<p><code>rmtree()<\/code>&nbsp;is a method under the&nbsp;<strong>shutil<\/strong>&nbsp;module which removes a directory and its contents in a&nbsp;<strong>recursive<\/strong>&nbsp;manner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-syntax-1\"><span class=\"ez-toc-section\" id=\"Syntax-2\"><\/span><strong>Syntax:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>S<em>hutil.rmtree(path, ignore_errors=False, onerror=None)<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-parameters-1\"><span class=\"ez-toc-section\" id=\"Parameters-2\"><\/span>Parameters:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>path:&nbsp;<\/strong><em>A path-like object representing a file path. A path-like object is either a string or bytes object representing a path.<\/em><br><strong>ignore_errors:<\/strong><em>&nbsp;If ignore_errors is true, errors resulting from failed removals will be ignored.<\/em><br><strong>oneerror:<\/strong><em>&nbsp;If ignore_errors is false or omitted, such errors are handled by calling a handler specified by onerror.<\/em><\/p>\n\n\n\n<p>Let&#8217;s see an example do delete a file using python script.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-python-program-to-delete-a-file-using-shutil-rmtree\"><span class=\"ez-toc-section\" id=\"Example_Python_Program_to_Delete_a_File_Using_shutilrmtree\"><\/span>Example: Python Program to Delete a File Using shutil.rmtree()<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Python program to demonstrate shutil.rmtree() \n\t\n<a href=\"http:\/\/www.pythonpool.com\/python-shutil\/\" target=\"_blank\" rel=\"noreferrer noopener\"><a href=\"http:\/\/www.pythonpool.com\/python-shutil\/\" target=\"_blank\" rel=\"noreferrer noopener\">import shutil<\/a><\/a> \nimport os \n\t\n# location \nlocation = \"E:\/Projects\/PythonPool\/\"\n\t\n# directory \ndir = \"Test\"\n\t\n# path \npath = os.path.join(location, dir) \n\t\n# removing directory \nshutil.rmtree(path) <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>It will delete the entire directory of files inside Test including the Test folder itself.<\/p>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-python-delete-file-using-pathlib-path-unlink\"><span class=\"ez-toc-section\" id=\"Python_Delete_File_Using_pathlibPathunlink\"><\/span>Python Delete File Using pathlib.Path.unlink()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The <strong>pathlib <\/strong>module is available in Python 3.4 and above. If you want to use this module in Python 2 you can install it with pip.&nbsp;<code>pathlib<\/code>&nbsp;provides an object-oriented interface for working with filesystem paths for different operating systems.<\/p>\n\n\n\n<p>To delete a file with the<code>pathlib<\/code>&nbsp;module, create a&nbsp;<code>Path<\/code>&nbsp;object pointing to the file and call the&nbsp;<code>unlink()<\/code>&nbsp;method on the object:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-python-program-to-delete-a-file-using-pathlib\"><span class=\"ez-toc-section\" id=\"Example_Python_Program_to_Delete_a_File_Using_pathlib\"><\/span>Example: Python Program to Delete a File Using pathlib<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#Example of file deletion by pathlib\n \nimport pathlib\n \nrem_file = pathlib.Path(\"pythonpool\/testfile.txt\")\n\nrem_file.unlink()<\/code><\/pre>\n\n\n\n<p>In the above example, the&nbsp;<code>path()<\/code>&nbsp;method is used to retrieve the file path whereas, the&nbsp;<code>unlink()<\/code>&nbsp;method is used to unlink or remove the file for the specified path.<\/p>\n\n\n\n<p>The unlink() method works for files. If a directory is specified, an <a href=\"http:\/\/www.pythonpool.com\/oserror-errno22-invalid-argument-solved\/\" target=\"_blank\" rel=\"noreferrer noopener\">OSError<\/a> is raised. To remove a directory, we can resort to one of the previously discussed methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-using-pathlib-path-rmdir-to-remove-empty-directory\"><span class=\"ez-toc-section\" id=\"Using_pathlibPathrmdir_to_remove_Empty_Directory\"><\/span><span class=\"has-inline-color has-vivid-red-color\">Using pathlib.Path.rmdir() to remove Empty Directory<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Pathlib module provides different ways to interact with your files. Rmdir is one of the path functions which allows you to delete an empty folder. Firstly, you need to select the Path() for the directory, and then calling rmdir() method will check the folder size. If it&#8217;s empty, it&#8217;ll delete it.<\/p>\n\n\n\n<p>This is a good way to deleting empty folders without any fear of losing actual data.<\/p>\n\n\n\n<p><strong>Example &#8211;<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom pathlib import Path\nq = Path('foldername')\nq.rmdir()\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-references-and-must-read\"><span class=\"ez-toc-section\" id=\"References_and_Must_Read\"><\/span>References and Must Read<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.pythonpool.com\/python-lowercase\/\">How to Convert String to Lowercase in Python<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/square-root-in-python\/\">How to Calculate Square Root in Python<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-user-input\/\">Python User Input | Python Input () Function | Keyboard Input<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-book\/\">Best Book to Learn Python in 2020<\/a> <\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/os.html#os.remove\" target=\"_blank\">https:\/\/docs.python.org\/3\/library\/os.html#os.remove<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/shutil.html\" target=\"_blank\">https:\/\/docs.python.org\/3\/library\/shutil.html<\/a><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/pathlib.html\" target=\"_blank\">https:\/\/docs.python.org\/3\/library\/pathlib.html<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learned various best ways to Python Delete File. The syntax to&nbsp;delete a file or folder using Python is quite simple. However, please be advised that once you&nbsp;execute the above commands, your file or folder would be&nbsp;<em>permanently<\/em>&nbsp;deleted.<\/p>\n\n\n\n<p>If you still have any doubts regarding Python Delete File. Do let us know in the comment section below.<\/p>\n\n\n\n<p><em><strong>Happy Coding!<\/strong><\/em><\/p>\n\n\n\n<p> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many times a user or a python programmer needs to delete a file. The reason maybe he\/she created the file by mistake, or there is &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"[Best] Ways to Delete a File in Python\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#more-2905\" aria-label=\"More on [Best] Ways to Delete a File in Python\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2931,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[743,746,744,737,749,752,735,738,750,736,734,732,731,747,733,739,741,742,751,753,730,748,745],"class_list":["post-2905","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-delete-a-file-in-python","tag-delete-a-file-python","tag-delete-file-in-python","tag-delete-file-python","tag-delete-file-python-3","tag-delete-file-using-python","tag-delete-line-from-file-python","tag-how-to-delete-a-file-in-python","tag-how-to-delete-a-file-python","tag-how-to-delete-file-in-python","tag-os-delete-file-python","tag-python-delete-a-file","tag-python-delete-file","tag-python-delete-file-if-exist","tag-python-delete-file-if-exists","tag-python-delete-file-if-it-exists","tag-python-delete-file-in-directory","tag-python-delete-line-from-file","tag-python-file-delete","tag-python-how-to-delete-a-file","tag-python-os-delete-file","tag-python-read-and-delete-line-from-file","tag-python-shutil-delete-file","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Best] Ways to Delete a File in Python - Python Pool<\/title>\n<meta name=\"description\" content=\"There are multiple ways to Delete a File in Python but the best ways are the following: os.remove(), os.unlink(), shutil.rmtree(), pathlib.Path.unlink()\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Best] Ways to Delete a File in Python\" \/>\n<meta property=\"og:description\" content=\"Many times a user or a python programmer needs to delete a file. The reason maybe he\/she created the file by mistake, or there is no need for that file\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-delete-file\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-22T11:54:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-27T03:42:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1017\" \/>\n\t<meta property=\"og:image:height\" content=\"614\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Python Pool\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Python Pool\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/\"},\"author\":{\"name\":\"Python Pool\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\"},\"headline\":\"[Best] Ways to Delete a File in Python\",\"datePublished\":\"2020-02-22T11:54:33+00:00\",\"dateModified\":\"2021-06-27T03:42:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/\"},\"wordCount\":1486,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg\",\"keywords\":[\"delete a file in python\",\"delete a file python\",\"delete file in python\",\"delete file python\",\"delete file python 3\",\"delete file using python\",\"delete line from file python\",\"how to delete a file in python\",\"how to delete a file python\",\"how to delete file in python\",\"os delete file python\",\"python delete a file\",\"python delete file\",\"python delete file if exist\",\"python delete file if exists\",\"python delete file if it exists\",\"python delete file in directory\",\"python delete line from file\",\"python file delete\",\"python how to delete a file\",\"python os delete file\",\"python read and delete line from file\",\"python shutil delete file\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-delete-file\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-delete-file\/\",\"name\":\"[Best] Ways to Delete a File in Python - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg\",\"datePublished\":\"2020-02-22T11:54:33+00:00\",\"dateModified\":\"2021-06-27T03:42:22+00:00\",\"description\":\"There are multiple ways to Delete a File in Python but the best ways are the following: os.remove(), os.unlink(), shutil.rmtree(), pathlib.Path.unlink()\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-delete-file\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg\",\"width\":1017,\"height\":614,\"caption\":\"python delete file\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-delete-file\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Best] Ways to Delete a File in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998\",\"name\":\"Python Pool\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"caption\":\"Python Pool\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"[Best] Ways to Delete a File in Python - Python Pool","description":"There are multiple ways to Delete a File in Python but the best ways are the following: os.remove(), os.unlink(), shutil.rmtree(), pathlib.Path.unlink()","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/python-delete-file\/","og_locale":"en_US","og_type":"article","og_title":"[Best] Ways to Delete a File in Python","og_description":"Many times a user or a python programmer needs to delete a file. The reason maybe he\/she created the file by mistake, or there is no need for that file","og_url":"https:\/\/www.pythonpool.com\/python-delete-file\/","og_site_name":"Python Pool","article_published_time":"2020-02-22T11:54:33+00:00","article_modified_time":"2021-06-27T03:42:22+00:00","og_image":[{"width":1017,"height":614,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg","type":"image\/jpeg"}],"author":"Python Pool","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Python Pool","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-delete-file\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-delete-file\/"},"author":{"name":"Python Pool","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998"},"headline":"[Best] Ways to Delete a File in Python","datePublished":"2020-02-22T11:54:33+00:00","dateModified":"2021-06-27T03:42:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-delete-file\/"},"wordCount":1486,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg","keywords":["delete a file in python","delete a file python","delete file in python","delete file python","delete file python 3","delete file using python","delete line from file python","how to delete a file in python","how to delete a file python","how to delete file in python","os delete file python","python delete a file","python delete file","python delete file if exist","python delete file if exists","python delete file if it exists","python delete file in directory","python delete line from file","python file delete","python how to delete a file","python os delete file","python read and delete line from file","python shutil delete file"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-delete-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-delete-file\/","url":"https:\/\/www.pythonpool.com\/python-delete-file\/","name":"[Best] Ways to Delete a File in Python - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg","datePublished":"2020-02-22T11:54:33+00:00","dateModified":"2021-06-27T03:42:22+00:00","description":"There are multiple ways to Delete a File in Python but the best ways are the following: os.remove(), os.unlink(), shutil.rmtree(), pathlib.Path.unlink()","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-delete-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-delete-file\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-delete-file\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/02\/Capture-26.jpg","width":1017,"height":614,"caption":"python delete file"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-delete-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"[Best] Ways to Delete a File in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/f87448ee54c0ffd2889fbf2408c18998","name":"Python Pool","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","caption":"Python Pool"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=2905"}],"version-history":[{"count":30,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2905\/revisions"}],"predecessor-version":[{"id":24431,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2905\/revisions\/24431"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/2931"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=2905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=2905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=2905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}