#f=open(r'你的路径/result.txt','w') #保存为txt
print(xxx,file=f)
f.close()
print的内容会保存到设置的路径文件中。
参考
[Python]将print结果保存到本地文件夹:https://blog.csdn.net/m0_54065225/article/details/115445181?utm_term=python%E6%8A%8Aprint%E4%BF%9D%E5%AD%98&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allsobaiduweb~default-0-115445181&spm=3001.4430