Python文件总结

2018-06-26  本文已影响0人  ARanEs

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()

上一篇 下一篇

猜你喜欢

热点阅读