Skip to content

Instantly share code, notes, and snippets.

@SaraM92
Created September 24, 2021 06:58
Show Gist options
  • Save SaraM92/40a530cf0f776c9aed61bc0dae6869b6 to your computer and use it in GitHub Desktop.
Save SaraM92/40a530cf0f776c9aed61bc0dae6869b6 to your computer and use it in GitHub Desktop.
#Checking if a file exists in two ways
#1- Using the OS module
import os
exists = os.path.isfile('/path/to/file')
#2- Use the pathlib module for a better performance
from pathlib import Path
config = Path('/path/to/file')
if config.is_file():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment