# -*- codeing = utf-8 -*-
# @Time : 2021/12/29
# @Author : YueJian

'''
try:
print("------test------")
f = open("test.txt", "r")
print("------test2-----")
print(num)

except Exception as result:
print(result)
'''

import time

# try except finally
'''
try:
f=open("gushi.txt","r")
try:
while True:
content = f.readline()
if len(content)==0:
break
time.sleep(2)
print(content)
finally:
f.close()
print("关闭文件")

except Exception as result:
print("发生异常")

'''
# 复制古诗
try:

f = open("gushi.txt", "r")
w = open("test.txt", "w")
try:
while True:
content = f.readline()
if len(content) == 0:
break
w.write(content)
finally:
print("复制完成")
f.close()
w.close()
except Exception as result:
print("发生异常")
print(result)
posted on 2021-12-30 16:47  Q_sword  阅读(35)  评论(0编辑  收藏  举报