{"id":2905,"date":"2020-02-22T17:24:33","date_gmt":"2020-02-22T11:54:33","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=2905"},"modified":"2026-07-13T12:26:39","modified_gmt":"2026-07-13T06:56:39","slug":"python-delete-file","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-delete-file\/","title":{"rendered":"Python Delete File: pathlib, os.remove(), and Safe Cleanup"},"content":{"rendered":"<p><strong>Quick answer:<\/strong> Use Path.unlink() or os.remove() to delete one file, and make the target explicit before removal. Resolve paths from input, keep them under an expected base directory, confirm the target type, close open handles, and choose a deliberate policy for missing files and permission errors.<\/p>\n<figure class=\"pythonpool-article-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-delete-file-b097.png\" alt=\"Python Pool infographic showing safe Python file deletion with pathlib, path validation, missing files, errors, and cleanup scope\" width=\"1536\" height=\"1024\" loading=\"lazy\" decoding=\"async\"><figcaption>Resolve and constrain the target, confirm it is a file, then use the narrowest deletion operation that matches the cleanup contract.<\/figcaption><\/figure>\n<p>Deleting a file in Python usually means calling <code>Path.unlink()<\/code> from <code>pathlib<\/code> or <code>os.remove()<\/code> from the <code>os<\/code> module. Both remove one file path. They do not remove a whole directory tree.<\/p>\n<p>The official Python documentation covers <a href=\"https:\/\/docs.python.org\/3\/library\/pathlib.html#pathlib.Path.unlink\">Path.unlink()<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/os.html#os.remove\">os.remove()<\/a>, and <a href=\"https:\/\/docs.python.org\/3\/library\/tempfile.html\">tempfile<\/a>.<\/p>\n<p>The safest habit is to build a known path, confirm it is the file you meant to remove, then delete it. Avoid hard-coded absolute paths in examples and tests. Temporary folders make file deletion easy to practice without touching real project data.<\/p>\n<p>Use <code>Path.unlink()<\/code> when you are already using <code>pathlib<\/code>. Use <code>os.remove()<\/code> when a project already uses older <code>os<\/code> path calls. Both approaches are valid, but modern code is often clearer with <code>Path<\/code> objects because path joining, existence checks, and deletion stay in one API.<\/p>\n<p>Also keep the operation narrow. A file delete should target one file. If the target is a folder, choose <code>Path.rmdir()<\/code> for an empty folder or <code>shutil.rmtree()<\/code> for a full tree after stronger path checks.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 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\/#Delete_A_File_With_pathlib\" >Delete A File With pathlib<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Ignore_A_Missing_File\" >Ignore A Missing File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Check_The_Path_Before_Deleting\" >Check The Path Before Deleting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Delete_A_File_With_osremove\" >Delete A File With os.remove<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Handle_Deletion_Errors\" >Handle Deletion Errors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Delete_Matching_Generated_Files\" >Delete Matching Generated Files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Choose_The_Right_Delete_Tool\" >Choose The Right Delete Tool<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Prefer_A_Narrow_Operation\" >Prefer A Narrow Operation<\/a><\/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\/#Constrain_User-Supplied_Paths\" >Constrain User-Supplied Paths<\/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\/#Choose_Missing-File_Behavior\" >Choose Missing-File Behavior<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Confirm_The_File_Type\" >Confirm The File Type<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Close_Handles_And_Handle_Errors\" >Close Handles And Handle Errors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Use_Narrow_Generated-File_Patterns\" >Use Narrow Generated-File Patterns<\/a><\/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\/#Test_Cleanup_In_Temporary_Directories\" >Test Cleanup In Temporary Directories<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#How_do_I_delete_a_file_in_Python\" >How do I delete a file in Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#How_do_I_ignore_a_missing_file\" >How do I ignore a missing file?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#Does_Pathunlink_delete_directories\" >Does Path.unlink() delete directories?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.pythonpool.com\/python-delete-file\/#How_can_I_make_file_deletion_safer\" >How can I make file deletion safer?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Delete_A_File_With_pathlib\"><\/span>Delete A File With pathlib<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>Path.unlink()<\/code> removes the file represented by a <code>Path<\/code> object. This example creates a temporary file first, then removes only that file.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from pathlib import Path\nimport tempfile\n\nwith tempfile.TemporaryDirectory() as folder:\n    path = Path(folder) \/ \"old-report.txt\"\n    path.write_text(\"temporary report\\n\", encoding=\"utf-8\")\n\n    print(path.exists())\n    path.unlink()\n    print(path.exists())\n<\/code><\/pre>\n<\/div>\n<p>The first print shows that the file exists before deletion. The second print shows that the same path no longer points to a file.<\/p>\n<p>This pattern is useful in tests, examples, and cleanup jobs because the temporary folder is isolated. The code creates the file it later removes, so the example does not depend on a file already being present on your machine.<\/p>\n<p>If the path points to a directory instead of a file, <code>Path.unlink()<\/code> raises an error. That is helpful because it prevents a file cleanup routine from silently removing the wrong kind of path.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Ignore_A_Missing_File\"><\/span>Ignore A Missing File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When absence is expected, pass <code>missing_ok=True<\/code> to <code>Path.unlink()<\/code>. This avoids a <code>FileNotFoundError<\/code> for a file that has already been removed.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from pathlib import Path\nimport tempfile\n\nwith tempfile.TemporaryDirectory() as folder:\n    path = Path(folder) \/ \"cache.txt\"\n    path.write_text(\"cached data\\n\", encoding=\"utf-8\")\n\n    path.unlink(missing_ok=True)\n    path.unlink(missing_ok=True)\n\n    print(path.exists())\n<\/code><\/pre>\n<\/div>\n<p>The second call does nothing because the file is already gone. This is a good fit for cache cleanup, test teardown, and repeated maintenance tasks where the final state matters more than whether this run removed the file.<\/p>\n<p>Do not use <code>missing_ok=True<\/code> everywhere. If a file must exist before deletion, let the exception reveal a broken assumption. Suppressing expected absence is useful; hiding unexpected absence can make bugs harder to diagnose.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Check_The_Path_Before_Deleting\"><\/span>Check The Path Before Deleting<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When a path comes from input, config, or another part of a program, resolve it and keep it under a known base directory before deletion.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from pathlib import Path\nimport tempfile\n\nwith tempfile.TemporaryDirectory() as folder:\n    base = Path(folder).resolve()\n    target = (base \/ \"uploads\" \/ \"draft.txt\").resolve()\n\n    target.parent.mkdir()\n    target.write_text(\"draft content\\n\", encoding=\"utf-8\")\n\n    if base not in target.parents:\n        raise ValueError(f\"Refusing path outside cleanup area: {target}\")\n    if not target.is_file():\n        raise FileNotFoundError(target)\n\n    target.unlink()\n    print(target.exists())\n<\/code><\/pre>\n<\/div>\n<p>The parent check keeps the deletion inside the temporary cleanup area. This matters when paths are assembled from user input, command-line arguments, job settings, or names read from a file.<\/p>\n<p>Resolve paths before comparing them. A path that contains <code>..<\/code> may look harmless before resolution but point somewhere else afterward.<\/p>\n<p>For command-line tools, prefer a base directory plus a relative name instead of accepting any absolute path. That keeps the cleanup boundary small and easy to review.<\/p>\n<p><!-- Python Pool visual layout repair 2026-07-13 --><\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/delete-file-path-b189.png\" alt=\"Python Pool infographic showing pathlib Path, a file, existence, and safe deletion\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>File path: Pathlib Path, a file, existence, and safe deletion.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Delete_A_File_With_osremove\"><\/span>Delete A File With os.remove<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code>os.remove()<\/code> and <code>os.unlink()<\/code> remove a file path. The names are equivalent for normal file deletion.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from pathlib import Path\nimport os\nimport tempfile\n\nwith tempfile.NamedTemporaryFile(delete=False) as handle:\n    path = Path(handle.name)\n    handle.write(b\"remove me\\n\")\n\nprint(path.exists())\nos.remove(path)\nprint(path.exists())\n<\/code><\/pre>\n<\/div>\n<p>This example uses <code>NamedTemporaryFile(delete=False)<\/code> so the file remains available after the file handle closes. Then <code>os.remove()<\/code> deletes it.<\/p>\n<p>Use this form when maintaining code that already uses <code>os<\/code> functions. Newer code can usually use <code>Path.unlink()<\/code> for the same job and keep path operations together.<\/p>\n<p>On Windows, open file handles can block deletion in some situations. Close the file before deleting it, or use a context manager so Python closes it before the remove call runs.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Handle_Deletion_Errors\"><\/span>Handle Deletion Errors<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Deletion can fail because the file is missing, the path is a directory, permissions are insufficient, or another process is using the file. Catch only the errors your code can handle.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from pathlib import Path\nimport tempfile\n\nwith tempfile.TemporaryDirectory() as folder:\n    missing = Path(folder) \/ \"missing.txt\"\n    directory = Path(folder) \/ \"not-a-file\"\n    directory.mkdir()\n\n    try:\n        missing.unlink()\n    except FileNotFoundError:\n        print(\"file was already absent\")\n\n    try:\n        directory.unlink()\n    except (IsADirectoryError, PermissionError):\n        print(\"path is a directory\")\n<\/code><\/pre>\n<\/div>\n<p>Keeping separate handlers makes the result easier to understand. A missing file may be acceptable in cleanup code, while a directory path usually means the caller gave the wrong target.<\/p>\n<p>Permission errors deserve a different response. You might log the path, stop the job, or ask the user to close another program. Do not turn every deletion failure into a silent pass.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Delete_Matching_Generated_Files\"><\/span>Delete Matching Generated Files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For generated files, combine a narrow base directory with a narrow pattern. Create the files under that base, then delete only the names that match the cleanup rule.<\/p>\n<div class=\"pythonpool-code-scroll\" style=\"max-width:100%;overflow-x:auto;-webkit-overflow-scrolling:touch;\">\n<pre><code class=\"language-python\">from pathlib import Path\nimport tempfile\n\nwith tempfile.TemporaryDirectory() as folder:\n    base = Path(folder)\n    for name in (\"run-1.tmp\", \"run-2.tmp\", \"keep.txt\"):\n        (base \/ name).write_text(\"generated\\n\", encoding=\"utf-8\")\n\n    for path in base.glob(\"*.tmp\"):\n        if path.is_file():\n            path.unlink()\n\n    remaining = sorted(path.name for path in base.iterdir())\n    print(remaining)\n<\/code><\/pre>\n<\/div>\n<p>The pattern removes only files ending in <code>.tmp<\/code> inside the temporary folder. The normal text file remains.<\/p>\n<p>Be careful with broad patterns in important directories. A pattern such as <code>*<\/code> is rarely a good cleanup rule unless the directory exists only for generated output and is recreated by your program.<\/p>\n<p>For recurring jobs, log the base directory, the pattern, and the number of files removed. That makes a cleanup task auditable without printing every path in a large folder.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/delete-file-methods-b189.png\" alt=\"Python Pool infographic comparing pathlib unlink, os.remove, and shutil rmtree\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Delete methods: Pathlib unlink, os.remove, and shutil rmtree.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Choose_The_Right_Delete_Tool\"><\/span>Choose The Right Delete Tool<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Use <code>Path.unlink()<\/code> or <code>os.remove()<\/code> for one file. Use <code>Path.rmdir()<\/code> for an empty directory. Use <code>shutil.rmtree()<\/code> only when you intentionally need to remove a directory and everything inside it.<\/p>\n<p>The practical workflow is simple: create or identify the file, resolve the path when the target comes from input, confirm it is a file, keep it under an expected base directory, and delete it with the narrowest tool that matches the job.<\/p>\n<p>That approach keeps examples safe and production cleanup code predictable. File deletion should be boring, explicit, and easy to review.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Prefer_A_Narrow_Operation\"><\/span>Prefer A Narrow Operation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Path.unlink() and os.remove() remove one file or link. They are not directory-tree operations, which is useful protection against a cleanup routine silently expanding its scope. Use rmdir or rmtree only when directory removal is intentional.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/delete-file-guard-b189.png\" alt=\"Python Pool infographic mapping a path through checks, permissions, dry run, and deletion\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>Safe guard: A path through checks, permissions, dry run, and deletion.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Constrain_User-Supplied_Paths\"><\/span>Constrain User-Supplied Paths<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Resolve a target against a known base, check that the resolved path remains within that base, and avoid accepting arbitrary absolute paths when a relative name is sufficient. Path traversal should be rejected before any filesystem mutation.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Choose_Missing-File_Behavior\"><\/span>Choose Missing-File Behavior<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>missing_ok=True is appropriate for idempotent cache cleanup and teardown. Let FileNotFoundError surface when the file&#8217;s existence is part of the contract, because suppressing it can hide a broken producer or wrong path.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Confirm_The_File_Type\"><\/span>Confirm The File Type<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Check is_file when a directory would be dangerous, and handle symlinks according to the cleanup policy. A path that looks like a generated file can point elsewhere after resolution, so validation belongs immediately before deletion.<\/p>\n<figure class=\"pythonpool-article-visual pythonpool-supporting-visual\"><img src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/delete-file-check-b189.png\" alt=\"Python Pool infographic testing missing files, directories, symlinks, races, and validation\" width=\"1536\" height=\"1054\" loading=\"lazy\" decoding=\"async\"><figcaption>File checks: Missing files, directories, symlinks, races, and validation.<\/figcaption><\/figure>\n<h2><span class=\"ez-toc-section\" id=\"Close_Handles_And_Handle_Errors\"><\/span>Close Handles And Handle Errors<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Windows and other systems can refuse deletion while a file is open. Use context managers, catch only expected FileNotFoundError, IsADirectoryError, and PermissionError cases, and report the path and action when cleanup cannot proceed.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Use_Narrow_Generated-File_Patterns\"><\/span>Use Narrow Generated-File Patterns<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For batch cleanup, combine a dedicated output directory with an exact suffix or prefix and count what was removed. Avoid broad patterns in user or project directories, and test that protected files remain.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Test_Cleanup_In_Temporary_Directories\"><\/span>Test Cleanup In Temporary Directories<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Create the file under tempfile.TemporaryDirectory, exercise existing, missing, directory, permission, traversal, and repeated-delete cases, and assert the final filesystem state rather than only whether an exception occurred.<\/p>\n<p>The official <a href=\"https:\/\/docs.python.org\/3\/library\/pathlib.html#pathlib.Path.unlink\">Path.unlink reference<\/a>, <a href=\"https:\/\/docs.python.org\/3\/library\/os.html#os.remove\">os.remove reference<\/a>, and <a href=\"https:\/\/docs.python.org\/3\/library\/shutil.html#shutil.rmtree\">shutil.rmtree reference<\/a> define the deletion operations. Related guidance includes <a href=\"https:\/\/www.pythonpool.com\/python-check-if-file-exists\/\">existence checks<\/a> and <a href=\"https:\/\/www.pythonpool.com\/python-testing-framework\/\">filesystem tests<\/a>.<\/p>\n<p>For related filesystem boundaries, compare <a href=\"https:\/\/www.pythonpool.com\/python-check-if-file-exists\/\">existence checks<\/a>, <a href=\"https:\/\/www.pythonpool.com\/python-tempfile\/\">temporary paths<\/a>, and <a href=\"https:\/\/www.pythonpool.com\/python-copy-file\/\">copying behavior<\/a> before writing a cleanup job.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_delete_a_file_in_Python\"><\/span>How do I delete a file in Python?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use Path.unlink() from pathlib or os.remove() for one file, after checking that the resolved target is the intended file.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_do_I_ignore_a_missing_file\"><\/span>How do I ignore a missing file?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Call Path.unlink(missing_ok=True) when absence is expected, or catch FileNotFoundError when the caller needs a more explicit policy.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Does_Pathunlink_delete_directories\"><\/span>Does Path.unlink() delete directories?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>No. Path.unlink() targets files or links; use Path.rmdir() for an empty directory or shutil.rmtree() only when intentionally removing a directory tree.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_can_I_make_file_deletion_safer\"><\/span>How can I make file deletion safer?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Keep the target under an expected base directory, resolve path traversal, check its type, close open handles, and use a narrow filename pattern for generated files.<\/p>\n<p><script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"How do I delete a file in Python?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use Path.unlink() from pathlib or os.remove() for one file, after checking that the resolved target is the intended file.\"}},{\"@type\":\"Question\",\"name\":\"How do I ignore a missing file?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Call Path.unlink(missing_ok=True) when absence is expected, or catch FileNotFoundError when the caller needs a more explicit policy.\"}},{\"@type\":\"Question\",\"name\":\"Does Path.unlink() delete directories?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. Path.unlink() targets files or links; use Path.rmdir() for an empty directory or shutil.rmtree() only when intentionally removing a directory tree.\"}},{\"@type\":\"Question\",\"name\":\"How can I make file deletion safer?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Keep the target under an expected base directory, resolve path traversal, check its type, close open handles, and use a narrow filename pattern for generated files.\"}}]}<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delete files safely in Python with pathlib.Path.unlink(), os.remove(), missing_ok, path validation, errors, and narrow cleanup patterns.<\/p>\n","protected":false},"author":1,"featured_media":34216,"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 v28.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Delete File: pathlib, os.remove(), and Safe Cleanup<\/title>\n<meta name=\"description\" content=\"Delete files safely in Python with pathlib.Path.unlink(), os.remove(), missing_ok, path validation, errors, and narrow cleanup patterns.\" \/>\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=\"Python Delete File: pathlib, os.remove(), and Safe Cleanup\" \/>\n<meta property=\"og:description\" content=\"Delete files safely in Python with pathlib.Path.unlink(), os.remove(), missing_ok, path validation, errors, and narrow cleanup patterns.\" \/>\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=\"2026-07-13T06:56:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-delete-file-b097.png\" \/>\n<meta name=\"author\" content=\"Python Pool\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Python Pool\" \/>\n<meta name=\"twitter:description\" content=\"Practical Python tutorials, error fixes, code examples, and project guides.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-delete-file-b097.png\" \/>\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\":\"Python Delete File: pathlib, os.remove(), and Safe Cleanup\",\"datePublished\":\"2020-02-22T11:54:33+00:00\",\"dateModified\":\"2026-07-13T06:56:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/python-delete-file\\\/\"},\"wordCount\":1398,\"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\\\/2026\\\/07\\\/python-delete-file-guide-pythonpool.png\",\"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\":\"Python Delete File: pathlib, os.remove(), and Safe Cleanup\",\"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\\\/2026\\\/07\\\/python-delete-file-guide-pythonpool.png\",\"datePublished\":\"2020-02-22T11:54:33+00:00\",\"dateModified\":\"2026-07-13T06:56:39+00:00\",\"description\":\"Delete files safely in Python with pathlib.Path.unlink(), os.remove(), missing_ok, path validation, errors, and narrow cleanup patterns.\",\"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\\\/2026\\\/07\\\/python-delete-file-guide-pythonpool.png\",\"contentUrl\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/python-delete-file-guide-pythonpool.png\",\"width\":1350,\"height\":650,\"caption\":\"Python delete file guide with pathlib unlink\"},{\"@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\":\"Python Delete File: pathlib, os.remove(), and Safe Cleanup\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pythonpool.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pythonpool.com\\\/\",\"name\":\"Python Pool\",\"description\":\"Practical Python tutorials, error fixes, code examples, and project guides.\",\"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\":\"https:\\\/\\\/www.pythonpool.com\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/aa.png\",\"contentUrl\":\"https:\\\/\\\/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:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g\",\"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":"Python Delete File: pathlib, os.remove(), and Safe Cleanup","description":"Delete files safely in Python with pathlib.Path.unlink(), os.remove(), missing_ok, path validation, errors, and narrow cleanup patterns.","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":"Python Delete File: pathlib, os.remove(), and Safe Cleanup","og_description":"Delete files safely in Python with pathlib.Path.unlink(), os.remove(), missing_ok, path validation, errors, and narrow cleanup patterns.","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":"2026-07-13T06:56:39+00:00","og_image":[{"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-delete-file-b097.png","type":"","width":"","height":""}],"author":"Python Pool","twitter_card":"summary_large_image","twitter_title":"Python Pool","twitter_description":"Practical Python tutorials, error fixes, code examples, and project guides.","twitter_image":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-delete-file-b097.png","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":"Python Delete File: pathlib, os.remove(), and Safe Cleanup","datePublished":"2020-02-22T11:54:33+00:00","dateModified":"2026-07-13T06:56:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-delete-file\/"},"wordCount":1398,"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\/2026\/07\/python-delete-file-guide-pythonpool.png","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":"Python Delete File: pathlib, os.remove(), and Safe Cleanup","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\/2026\/07\/python-delete-file-guide-pythonpool.png","datePublished":"2020-02-22T11:54:33+00:00","dateModified":"2026-07-13T06:56:39+00:00","description":"Delete files safely in Python with pathlib.Path.unlink(), os.remove(), missing_ok, path validation, errors, and narrow cleanup patterns.","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\/2026\/07\/python-delete-file-guide-pythonpool.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2026\/07\/python-delete-file-guide-pythonpool.png","width":1350,"height":650,"caption":"Python delete file guide with pathlib unlink"},{"@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":"Python Delete File: pathlib, os.remove(), and Safe Cleanup"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Practical Python tutorials, error fixes, code examples, and project guides.","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":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"https:\/\/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:\/\/secure.gravatar.com\/avatar\/fdd3cb9ad7f560324dfd481989550aa8ffce84388fd253c42beca35c999d3108?s=96&d=wavatar&r=g","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":37,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2905\/revisions"}],"predecessor-version":[{"id":41358,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/2905\/revisions\/41358"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/34216"}],"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}]}}