-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek4assignment.py
More file actions
22 lines (17 loc) · 810 Bytes
/
week4assignment.py
File metadata and controls
22 lines (17 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def read_and_modify_file_with_error_handling():
input_file = input("Enter the input filename: ")
output_file = input("Enter the output filename: ")
try:
with open(input_file, 'r') as file:
content = file.readlines()
# Modify the content as needed. For example, let's convert all text to uppercase.
modified_content = [line.upper() for line in content]
with open(output_file, 'w') as file:
file.writelines(modified_content)
print(f"Modified content has been written to {output_file}")
except FileNotFoundError:
print(f"The file {input_file} does not exist.")
except IOError:
print(f"An error occurred while reading from or writing to the file.")
# Example usage:
read_and_modify_file_with_error_handling()