What code needs to be in the “with…as… :” block of code? For example, does “print(first_line)” need to be in this block? How do I know when I can leave this code block?
Using a with statement, create a file object pointing to the file just_the_first.txt . Store that file object in the variable first_line_doc .
I typed:
with open ('just_the_first.txt') as first_line_doc:
And it’s not letting me advance to the next step. I’ve been staring at this for about ten minutes, and finally just skipped ahead and did the other greyed-out steps, and successfully printed out the first line, but it’s still not letting me advance.
The little black popup keeps asking, by the way:
Did you open just_the_first.txt as first_line_doc ?
So, what stupidly obvious thing am I missing here?
How does python know to read the second line when you run readline() for a second time? This is the first piece of code I have encountered that acts differently based on how many times it has been called previously in a script. For instance, I would expect that