Read the given file, if it exists. Args: filename: A path to a file. Returns: A string containing the file contents, or `None` if the file does not exist.
(filename)
| 509 | |
| 510 | |
| 511 | def _maybe_read_file(filename): |
| 512 | """Read the given file, if it exists. |
| 513 | |
| 514 | Args: |
| 515 | filename: A path to a file. |
| 516 | |
| 517 | Returns: |
| 518 | A string containing the file contents, or `None` if the file does |
| 519 | not exist. |
| 520 | """ |
| 521 | try: |
| 522 | with open(filename) as infile: |
| 523 | return infile.read() |
| 524 | except IOError as e: |
| 525 | if e.errno == errno.ENOENT: |
| 526 | return None |