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

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -