Returns a file descriptor for the filename if that file exists, otherwise ``None``.
(filename: str, mode: str = "rb")
| 153 | |
| 154 | |
| 155 | def open_if_exists(filename: str, mode: str = "rb") -> t.Optional[t.IO]: |
| 156 | """Returns a file descriptor for the filename if that file exists, |
| 157 | otherwise ``None``. |
| 158 | """ |
| 159 | if not os.path.isfile(filename): |
| 160 | return None |
| 161 | |
| 162 | return open(filename, mode) |
| 163 | |
| 164 | |
| 165 | def object_type_repr(obj: t.Any) -> str: |