Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Exception Type with except block:

#!/usr/bin/env python3

try:
    with open('input.txt', 'r') as myfile:
        for line in myfile:
            print(line)
except FileNotFoundError:
    print('Sorry, file doesn't exist')
except PermissionError:
    print('Sorry, you don't have permission to access the file')

print('Outside the with block')
Source by www.golinuxcloud.com #
 
PREVIOUS NEXT
Tagged: #Exception #Type
ADD COMMENT
Topic
Name
5+6 =