try: f = open('aaa.txt','w') for each_line in f: print(each_line) except Exception as reason: print('Your error is :n' + str(reason)) finally: f.close()
与以下效果相同:
1 2 3 4 5 6
try: with open('aaa.txt','w') as f: for each_line in f: print(each_line) except Exception as reason: print('Your error is :n' + str(reason))
近期评论