Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Reading from Files

fahad lashari
fahad lashari
7,693 Points

How do I delete something specific from a file? Python I/O

Upon doing my own research I found that most people re-write the whole file without the piece of data they want to delete. It seems very inefficient. Is there anyway of simply deleting that specific piece of data and not have to touch anything else?

kind regards,

Fahad

1 Answer

Hello again Fahad,

Soon, you will learn about regex (regular expressions) in Python.

import re

This library will solve all your problems.

Until then, sit tight!

If you have any other questions I will update my answer, if you do not have any other questions:

Remember to upvote and to choose the best answer so that your question receives a checkmark in forums.

Kind regards,

Leo