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 trialpeter keves
6,854 Pointsopen read and close methods
Although Kenneth provided us in teacher's notes with the terms definition I still can't get my head around this methods, for example why do we even have to use it ? can't we just use re.findall on a regular text ? and its not clear to me what does methods do can someone help me ?
1 Answer
Ira Bradley
12,976 Pointsopen, read and close are used for accessing data that lives in a file outside of our python script. Open creates a pointer to the file we want to manipulate. You can think of the pointer as pointing at the very first line in the file. Read grabs all the text from inside of the file. You can imagine the pointer moving through the file line by line from top to bottom. Close closes the file. This prevents us from accidentally making changes to the file or corrupting the data. When we are done reading the file we are done with the file so we close it.
This is not unlike opening a text file on our computer for reading. We double-click on it to open, read it from top to bottom and then close it with one of the ways we usually close files.
Hope this helps.
peter keves
6,854 Pointspeter keves
6,854 Pointsthanks again :))) so everyime we want to use our regular expression we have to do open read and close process ?