$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #167

Which fix removes the bug?

with open(path) as f:
    pass
data = f.read()
  1. Read inside the block
  2. Reopen the file after
  3. Use open without with
  4. Flush before reading
The context manager closes the file on exit, so the later read fails.
Play Problem Solving ▸