Код: Выделить всё
#delete file
import os
file_path = r"The\\path_file"
try:
os.remove(file_path)
print("The file has been removed")
except FileNotFoundError:
print("File not found.")
except PermissionError:
print("Access denied. You don't have permission to remove this file.")
except Exception as e:
print(f"An error occurred: {e}")
чтобы понять, что на самом деле происходит, я поставил условие try execpt:
Код: Выделить всё
try: os.remove(file_path) print("The file has been removed") except FileNotFoundError: print("File not found.") except PermissionError: print("Access denied. You don't have permission to remove this file.") except Exception as e: print(f"An error occurred: {e}")Подробнее здесь: https://stackoverflow.com/questions/790 ... ule-python