Python Forum
Delete all contents of a file from the fifth line?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete all contents of a file from the fifth line?
#1
Hello,

I want to delete all the contents of the file from under the fifth line.

Is this doable?
I don't want to just print the file on the console, I actually want the contents of the file to be deleted from the fifth line and then to be saved.

I tried searching on the internet but was not able to find anything, maybe I just suck search at searching.

Can anyone help?
Thank you.
Reply


Messages In This Thread
Delete all contents of a file from the fifth line? - by PythonNPC - Apr-18-2020, 08:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 138 Yesterday, 07:23 AM
Last Post: Pedroski55
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,651 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Getting last line of each line occurrence in a file tester_V 1 889 Jan-31-2023, 09:29 PM
Last Post: deanhystad
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,410 Sep-27-2022, 01:38 PM
Last Post: buran
  Delete multiple lines from txt file Lky 6 2,342 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Print to a New Line when Appending File DaveG 0 1,238 Mar-30-2022, 04:14 AM
Last Post: DaveG
  Find and delete above a certain line in text file cubangt 12 3,546 Mar-18-2022, 07:49 PM
Last Post: snippsat
  [Solved] Delete a line in a dataframe using .reset_index() and .drop() ju21878436312 2 2,714 Feb-25-2022, 02:55 PM
Last Post: ju21878436312
  CSV to Text File and write a line in newline atomxkai 4 2,745 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  How to delete portion of file already processed? Mark17 13 2,797 Jan-22-2022, 09:24 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020