Saturday, 26 April 2025

Python On Error reume next

try:
    # Code that may raise an exception
    with pd.ExcelWriter(file, engine='openpyxl', mode='a', if_sheet_exists='replace') as writer:
        partspec_insert.to_excel(writer, sheet_name='Existing Spec', index=False)
except Exception as e:
    # Handle the exception (e.g., log it, print it, or pass)
    print(f"An error occurred: {e}")
    # You can use 'pass' to ignore the error and continue execution
    pass

# Continue with the rest of your code 
print("Execution continues even if an error occurred.") 


No comments:

Post a Comment