About 14,500,000 results
Open links in new tab
  1. python - How to modify a text file? - Stack Overflow

    Sep 24, 2008 · I'm using Python, and would like to insert a string into a text file without deleting or copying the file. How can I do that?

  2. How to Modify a Text File in Python - AskPython

    May 19, 2023 · In this article, we're going to dive deep into file handling in Python, understand the ABCs of file handling, and then learn how to modify a text file.

  3. Editing specific line in text file in Python - Stack Overflow

    Jan 18, 2011 · my_file=open('data.txt') string_list = my_file.readlines() string_list[-1] = "Edit the list of strings as desired\n" my_file = open("data.txt", "w") new_file_contents = "". join(string_list) …

  4. How do I edit a text file in Python? - Stack Overflow

    Dec 31, 2014 · You can examine the file pointer by embedding text.tell() at different lines. Here is another approach: with open("file","r") as file: text=file.readlines() i=0 while i < len(text): if …

  5. Reading and Writing to text files in Python - GeeksforGeeks

    Jan 2, 2025 · There are three ways to read txt file in Python: Reading From a File Using read () read (): Returns the read bytes in form of a string. Reads n bytes, if no n specified, reads the …

  6. Python Program to Replace Text in a File - GeeksforGeeks

    Sep 5, 2024 · In this article, we are going to replace Text in a File using Python. Replacing Text could be either erasing the entire content of the file and replacing it with new text or it could …

  7. Python: Inplace Editing using FileInput - GeeksforGeeks

    Feb 19, 2020 · It comes handy in many places but in this article, we'll use the fileinput to do in-place editing in a text file. Basically we'll be changing the text in a text file without creating any …

  8. How to modify existing Python files | LabEx

    Learn efficient techniques to modify, edit, and manipulate existing Python files with comprehensive strategies for file handling, content editing, and advanced file modification …

  9. File Handling In Python - Python Guides

    Read the First Line of a File in Python; Save Images to a File in Python; Import All Functions from a File in Python; Get the Basename of a File in Python; Create a CSV File in Python; Write …

  10. How to Edit File in Python? - Pencil Programmer

    Jun 16, 2023 · Let’s see different ways to edit a file in Python. Use writelines() or write() to Write to File in Python # Open file for writing my_file = open("my_file.txt", "w") # Write to File …

  11. Some results have been removed
Refresh