wrting to txt file python code example
Example 1: python read file to variable
with open('data.txt', 'r') as file:
data = file.read().replace('\n', '')
Example 2: python output to text file
$ python my_program.py > output.txt
with open('data.txt', 'r') as file:
data = file.read().replace('\n', '')
$ python my_program.py > output.txt