美文网首页
Python文件总结

Python文件总结

作者: ARanEs | 来源:发表于2018-06-26 20:02 被阅读0次

1.文件的打开和关闭, 文件的读,写和追加

f=open("test","w")

content=f.write("the life is short , you need python")

print(content)

f.close()

f=open("test","r")

content=f.read(5)

print(content)

content=f.read()

print(content)

f.close()

f=open("test","a")

content=f.write("python is easy")

print(content)

f.close

2.文件的定位

f=open("test","r")

content=f.read(3)

print(content)

position=f.tell()

print(position)

f.seek(3,0)

content=f.read()

print(content)

f.close()

相关文章

网友评论

      本文标题:Python文件总结

      本文链接:https://www.haomeiwen.com/subject/spomyftx.html