write to a file in python line by line code example Example: python output to text file $ python my_program.py > output.txt