Test whether a path exists. Returns False for broken symbolic links
(path)
| 14 | # Does a path exist? |
| 15 | # This is false for dangling symbolic links on systems that support them. |
| 16 | def exists(path): |
| 17 | """Test whether a path exists. Returns False for broken symbolic links""" |
| 18 | try: |
| 19 | os.stat(path) |
| 20 | except (OSError, ValueError): |
| 21 | return False |
| 22 | return True |
| 23 | |
| 24 | |
| 25 | # Being true for dangling symbolic links is also useful. |