Aug 11, 2024
This is a great example of why LBYL can't possibly work.
First, there's a bug in the code - the file might exist but not be readable. You have no way to detect that bug in your code until you actually run into that condition, perhaps years from now.
But second, what happens if between the os.path.exists and the open, something changes: the file is deleted, the disk goes off line, the network connection to the remote disk fails?