Original txt content:
The last line of all txt in the folder is appended: 33 0.505794 0.947476 0.166326 0.055935. As shown in the picture:
import glob
import os
import shutil
Path=r"C:\Users\YUXIAOYANG\Desktop\labels"
for root,dirs,filename in os.walk(Path):
for i in range(len(filename)):
with open(root+"\\"+filename[i],'a') as f:
f.write('33 0.505794 0.947476 0.166326 0.055935'+'\n')
Knowledge points:
Reference blog: Python: Adding and reading to TXT files with existing content