文件读写
ascii函数 ord()函数 chr()函数
全局变量修改global 局部变量nonlocal
#写文件
f.write(‘sunck is a hate man’) # 将信息写入缓冲区
#刷新缓冲区
flush函数
f.flush() # 刷新缓冲区将内部缓冲区的数据写入文件 而不是等待关闭文件时写入
while True:
pass
f.close()
while True:
f.write(‘super man \n’)
f.flush() # 刷新缓冲区将内部缓冲区的数据写入文件 而不是等待关闭文件时写入
time.sleep(3)
f.close()
#文件简写
with open(path,‘a’,encoding=‘utf-8’) as f2:
f2.write(‘sunck is a badman’)
pickle函数
import pickle #数据持久性模块
mylist=[1,2,3,4,5]
path=r’F:\pycharm1807\day08\file05.txt’
f=open(path,‘wb’)
pickle.dump(mylist,f)
f.close()
#读取数据
f1=open(path,‘rb’)
tempList=pickle.load(f1)
print(tempList)
f1.close()