write all console output to file from a python script code example Example: redirect python output to file $ python foo.py > file