import uos def file_or_dir_exists(filename): try: uos.stat(filename) return True except OSError: return False