About 13,800,000 results
Open links in new tab
  1. How to delete data from file in Python - GeeksforGeeks

    Apr 22, 2025 · Let’s explore the various ways to delete data from files. Consider our sample file sample.txt, which contains the following data: This method is used when you want to …

  2. How to delete a specific line in a text file using Python?

    Mar 16, 2023 · First, open the file and get all your lines from the file. Then reopen the file in write mode and write your lines back, except for the line you want to delete: lines = f.readlines() for …

  3. Python: How to Delete a text from a file and save it - PyTutorial

    May 14, 2023 · By using replace () method, you can delete a phrase or text from a file. Let's see how to use it. Before writing our code, let's see the file.txt output. file.txt: Python is an …

  4. Delete Lines From a File in Python - PYnative

    Jul 3, 2021 · Learn How to remove lines from a file by line numbers. Remove lines that match the specific text. Delete first and Last lines from file.

  5. File Handling in Python

    Write to a File Without Newline in Python; Delete a File if it Exists in Python; Create a File in Python if It Doesn’t Exist; Write JSON Data to a File in Python; Close a File in Python; Save …

  6. Efficiently Deleting Text and Lines from Files in Python

    If you want to delete lines in a text file that contain a specific word or string, you can use Python’s “startswith()” method to search for the word or string in each line. If a line contains the desired …

  7. How to erase the file contents of text file in Python?

    Feb 26, 2017 · In Python: open('file.txt', 'w').close() Or alternatively, if you have already an opened file: f = open('file.txt', 'r+') f.truncate(0) # need '0' when using r+

  8. How to Delete a Specific Line in a File - PythonForBeginners.com

    Jun 10, 2021 · In this guide, we’ll cover several ways of removing lines from a text file using Python. We’ll see how to remove lines based on their position in the document and how to …

  9. Python Program to Delete Specific Line from File

    Sep 5, 2024 · In this article, we are going to see how to delete the specific lines from a file using Python. Throughout this program, as an example, we will use a text file named months.txt on …

  10. Delete Specific Line from a Text File in Python - Online Tutorials …

    Aug 1, 2022 · In this article, we will show you how to delete a specific/particular line from a text file using python. Assume we have taken a text file with the name TextFile.txt consisting of some …

  11. Some results have been removed
Refresh