📜  带有 except 块的异常类型:- Python 代码示例

📅  最后修改于: 2022-03-11 14:46:31.555000             🧑  作者: Mango

代码示例1
#!/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')