Is it correct to say that scope of ‘with’ in python files is until file is read once, or written to once, or appended once, or the passed parameter is fulfilled once?
with open(‘how_many_lines.txt’) as lines_doc:
for each_line in lines_doc.readlines():
after these lines of code, the following code does not work
each_line = lines_doc.read()
this does not work, i.e gives no output, but if i call ‘with’ again then it works.
So how to know ‘with’ scope for write and append instances??
The exercise i was trying was Iterating Through Lines
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!