【发布时间】:2018-02-22 22:50:22
【问题描述】:
使用 save_ouput 函数,如何保存每个函数的输出?
def a():
print("abc,")
def b():
print("help,")
def c():
print("please")
def save_output():
# save output of all functions
def main():
a()
b()
c()
save_output()
main()
^所以当 main 被调用时它会将abc,help,please保存为文本文件
【问题讨论】:
-
你的
save_output()函数没有任何作用。您需要明确告诉它您要保存什么以及要保存在哪里。应该有代码而不是评论#save output of all functions。 -
几种方法,你有没有找过一种尝试过?
-
@joaoavf 这是“在此处插入其他人的代码”的占位符。这就像参数化 SQL 语句的反面
-
我知道它需要代码,我只是不知道是什么。我试过了:
-
with io.open("abc.txt.", 'w') as f: with redirect_stdout(f): #What print statements here?
标签: python function save output