31 文件复制

#
#打开文件
file1 = open("test2.py")   #默认只读
file2=open("test2.py.copy","w")  # w 覆盖写, a 追加,没有文件都会创建

#读取文件
text = file1.read()
#写入文件
file2.write(text)


#关闭文件
file1.close()
file2.close()

 

#
file1 = open("test2.py")
file2=open("test2.py.copy","w")

while True:
    text = file1.readline()

    if not text:
        break

    file2.write(text)

file1.close()
file2.close()

 

posted @ 2020-06-12 23:43  abel2020  阅读(148)  评论(0编辑  收藏  举报