在每一个print后的括号里加上 file = f,例如: f = open("output.txt", "w") print(img,file = f) f.close() 这里可以不用手动创建output.txt,因为程序会自动创建