def main(): f =open('致橡树.txt','r',encoding='utf-8') print(f.read()) f.close() def test(): f= None try: f = open("致橡树.svb",'r',encoding='utf-8') print(f.read()) except FileNotFoundError: print("无法打开指定文件!") except LookupError: print('指定了未知的编码!') except UnicodeDecodeError: print('读取文件时解析错误!') finally: if f: f.close() if __name__ =="__main__": main() test()
标签:__,读取,python,抛错,except,未找到,print,main,致橡树 From: https://www.cnblogs.com/kevin-yang123/p/17023985.html