主页
Python
Python Try Except 异常处理
demo_try_except5
运行 ❯
×
更改方向
保存代码
更改主题
#The try block will raise an error when trying to write to a read-only file: try: f = open("demofile.txt") f.write("Lorum Ipsum") except: print("Something went wrong when writing to the file") finally: f.close() #The program can continue, without leaving the file object open
Something went wrong when writing to the file