Cody Bable

Generation

generate functionThu, 20 Apr 2023

try...except block checking if a file exist

def file_exists(filename): try: f = open(filename) f.close() return True except FileNotFoundError: return False file_exists('test.txt')

Want to kickstart your project?Use the new AI Studio to create your code