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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -