Posts

Showing posts from September, 2024

File operation

import os def create_file(file_name, content=""):     with open(file_name, 'w') as file:         file.write(content)     print(f"File '{file_name}' created successfully.") def delete_file(file_name):     if os.path.exists(file_name):         os.remove(file_name)         print(f"File '{file_name}' deleted successfully.")     else:         print(f"File '{file_name}' does not exist.") def update_file(file_name, content):     if os.path.exists(file_name):         with open(file_name, 'a') as file:             file.write(content)         print(f"File '{file_name}' updated successfully.")     else:         print(f"File '{file_name}' does not exist. Create the file first.") def invalid_operation(*args):     print("Invalid operation selected.") # Switch-case-...