how to redirect print output to a text file in python code example Example: redirect python output to file $ python foo.py > file