f =open("file.txt",'x') #文件存在报错,不存在创建并写
f =open('test.txt','rwa') #追加 w 只写先清空原文件 r 只读
f = open('db','r')
data=f.read()
print(data)
f.close()
f = open('db','ab')
f.write(bytes("小明",encoding="utf8"))
f.close()
# 如果打开模式没有用b,则读取一个字
符# 用b时则读取一个字节
f = open('db','r+')
f.read()
print(f.tell())
f.seek(f.tell()) #设置指针的位置 总是指字节
f.write("99999")
f.close()
"""
2 操作文件
read()无参数读全部,有b读字节,无b读字符
fush() 立即写到硬盘
truncat()根据指针位置清空文件
"""f = open('db','r',encoding="utf-8")
for line in f:
print(line)