how to create a file and write a line to it python code example Example: python output to text file $ python my_program.py > output.txt