📜  如何在python代码示例中打印到文件

📅  最后修改于: 2022-03-11 14:46:26.935000             🧑  作者: Mango

代码示例3
#you do not have to create a text file in advance, this program will create the file if it does not exist.
whatever = ('this is what will be printed to your file')
sourceFile = open('demo.txt', 'w')
print(whatever, file = sourceFile)
sourceFile.close()