将print输出结果保存到txt文件

years = [1,2,3,4,5,6]
f = open("c.txt", 'w+')
dicte=[]
cd={}
for i in years:
    print(i)
    years.remove(i)
    b=years
    dicte=b
    cd[i]=dicte
    print(dicte)
    print(years, file=f)
print(cd)

你可能感兴趣的:(将print输出结果保存到txt文件)