with open("my_file.txt", "w") as f: # File automatically closed f.write("Hello, Python!") try: with open("nonexistent_file.txt", "r") as f: #Handles potential errors gracefully content = f.read() except FileNotFoundError: print("File not found, but the program continues.")