上下文管理器

文件上下文管理器自动关闭文件

"""
with open() as 名字
student.txt
hello world
word ppt excel

"""
## 读取student的内容复制到b中
with open("student.txt","r") as f,open("b.txt","w+") as f2:
   f2.write(f.read())
   f2.seek(0,0)##因为读取后指针在最后所以需要将指针移动到开头
   print(f2.read())

 

posted @ 2021-04-23 17:50  默默努力的路人甲  阅读(34)  评论(0)    收藏  举报