我有一行代码打印出这样的段落:
print("An Apple a day keeps the doctor away ... ") #paragraph1
.
.
.
print("Two Apples a day keeps two doctors away ... ") #paragraph2
.
.
.
json.dump(someData) #paragraph3
我只是想将控制台中打印的所有段落都指向文件。
注意:
有没有可以实现此功能的功能? (将控制台中打印的所有段落一次写入文件?)
答案 0 :(得分:2)
将标准输出转移到文件
<body [ngClass]="'<class for overflow: hidden>': isMyDialogVisible" ...>
答案 1 :(得分:1)
尝试将段落存储到字符串变量中。它看起来像这样
p1 = "An Apple a day keeps the doctor away ... "
p2 = "Two Apples a day keeps two doctor away ... "
print(p1)
print(p2)
with open("output.txt", "w")as output:
p1and2 = p1 + p2
output.write(p1and2)
希望这有效