Writing the results of a function to a file in Python 2.7 -
i'm trying write results of function file; in code below, results not saved output file (it writes:"none"):
def program(): print "hello world!" open("output.txt", "w") output_file: output_file.write(str(program()))
the goal write entire output of script (not shown here) file within script; i'm guessing there's better way (stdout?) i'm beginner little knowledge ;-)
i've tried few workarounds same result, i've search answer couldn't find exact question. help!
use return
instead of printing:
def program(): return "hello world!"
without return
, function program
return none
value.
Comments
Post a Comment