The Quantum Garden

Life learning, for life

Buy me a coffee
David C. Buchan
Bendigo
Victoria
Australia
Business Technology Consultant
Home

❯

Notes

Delete single line from file using Python

4 June 2024

How to delete a line in text file using Python | Website Scripts And Cloud Tutorials (mistonline.in)

#!/usr/bin/python
def deleteLine():
 fn = 'myfile'
 f = open(fn)
 output = []
 str="The"
 for line in f:
   if not line.startswith(str):
    output.append(line)
 f.close()
 f = open(fn, 'w')
 f.writelines(output)
 f.close()
deleteLine()


Recent Blogs

  • Migrating from Quartz 4 to Quartz 5

    29 May 2026

  • Conversation for clarity

    22 May 2026

  • Finding my ontology tribe

    15 May 2026

  • Books are banned for power or fear

    5 May 2026

  • Now, 3 May 2026

    3 May 2026

See 565 more →

Graph View


  • Subscribe
  • About
  • |
  • Privacy
  • AI Policy
  • |
  • Mastodon
  • Github
© David C. Buchan 2002–2026. Last update: 31 May 2026 at 7:59 pm. Recently updated notes.
1420 site pages. Colophon. total unique visits.