1.文件的打开操作
f = open("1.txt","w")
2.文件的关闭操作
f = open("1.txt","w")
f = close()
3.文件的读写
f = open("1.txt","w")
f.write("我爱中国")
4.读数据(read) 读单个长度
f = open("1.txt","r")
content = f.read(5)
print(content)
print("*"*30)
content = f.rand()
print(content)
f.close()
5.读数据(readlines) 读所有行
f = open("1.txt","r")
content = f.randlines()
print(type(content))
i = 1
for temp in content:
print("%d:%s"%(i,temp))
i =+ 1
f.close()
6.读数据(readline)读一行
f = open("1.txt","r")
content = f.readline()
print("1:%s"%content)
content = f.readline()
print("2:%s"%content)
f.close()
网友评论