import time
with open ('access.log',mode='rb') as f:
#1将指针跳到文件末尾
#f.read() #错误做法
f.seek(0,2)
while True:
line = f.readline()
if len(line) == 0:
time.sleep(0.3)
else:
print(line.decode('utf-8')
下面往acess.log里面输入日志,上面可以动态监测到日志的一个变化
with open('access.log',mode='at',encoding='utf-8')as f:
f.write('20210312851 xxx转账100w\n')
f.write('20210312852 yyy转账200w\n')