piping - Python capture all printed output -
i looking write console based programs in python can execute functions perform generic tasks, pretty generic. possible capture written console print calls in function without needing return string, similar how bash , windows shell allow piping output of program text file, ie
ipconfig>ipconfig.txt
but doing inside of python program, function called, printed console inside of function gathered list of strings, , can saved txt file of users choice?
you can setting sys.stdout
file of choice
import sys sys.stdout = open('out.dat', 'w') print "hello" sys.stdout.close()
will not display output create file called out.dat
printed text.
note doesn't need actual file stringio instance, can use getvalue
method of access has been printed previously.
Comments
Post a Comment