When you do a = fsub()
, you're trying to assing a
the return of fsub()
, in this case None
(because fsub()
doesn't return anything).
The correct thing to do is to redirect the stdout to a file, then call the fsub()
function, and the redirect back the stdout to the original stdout:
import sys
def fmain():
sys.stdout = open('output','a')
fsub()
sys.stdout = sys.__stdout__
print 'Output of fsub():'
print open('output').read(),
# added the coma (,) to avoid a new line
Result:
>>> fmain()
Output of fsub():
OK