with管理上下文

#with open(文件路径,打开模式(rt/wt/at/rb/wb/ab),编码格式) as 变量名:
#     # 变量名.read/write
 with open('test.txt','r',encoding='utf8') as fr:
     data = fr.read()
     print(data)
 name='胡桃' 
 print(name)# 胡桃        #会在文件后加上
posted @ 2024-03-22 16:31  泥跟沃丸吗  阅读(4)  评论(0编辑  收藏  举报