open("文件名",操作方式)
import os
"""
# 2
f = open('abc.txt','r')
try:
date=f.read()
print(data)
finally:
f.close()
# 3 with as
with open("abc.txt",'r') as f: #可不写r 默认为r
data=f.read()
print(data)
"""
f = open('abc.txt','w')
f.write("hello\n")
f.write("MM")
f.close()
f=open('abc.txt','r')
str=f.read()
print(str)
f.close()
os.rename("abc.txt","aa.txt")
网友评论