11 lines
487 B
Python
11 lines
487 B
Python
# Write a Python program that opens a file and handles a UnicodeDecodeError exception if there is an encoding issue.
|
|
|
|
#Try opening the 'test.bin' file (which was created specifically for this problem) and assign it to 'f'
|
|
try:
|
|
with open('test.bin') as f:
|
|
# Attempt to read the 'test.bin' file
|
|
f.read()
|
|
# Handle the expected UnicodeDecodeError exception
|
|
except UnicodeDecodeError:
|
|
# Print the error message
|
|
print('There was an encoding problem with this file') |