Python 异常处理

July 4, 2022

Python异常处理 try-except。

异常处理

"""
异常处理
"""

try:
    with open("file/read.txt", encoding = "UTF-8") as file_obj:
        lines = file_obj.readlines()
except FileNotFoundError:
    # 或者 pass 关键字忽略错误
    print("file not found")
else:
    # 没有异常抛出时执行
    for line in lines:
        print(line)

    
PythonPython编程从入门到实战

IARNO

服务端开发

Cloc 代码统计

Python 文件篇