Put the data into a file. Let's call it data.txt.
To write to a file you do almost the same.
with open('data.txt', 'r') as data: for line in data: # do somethingHere is how you read from a file. You create a file object called data and iterate over each line. The 'r' parameter is for reading.
To write to a file you do almost the same.
with open('some_file.txt', 'w') as output: # this time in 'w' (write) mode for element in iterable: output.write(element)The
with
statement is called context manager and it will close the file automatically when its code block is executed. You can stack them.with open('file_one.txt', 'r') as r: with open('file_two.txt', 'w') as w: for line in r: w.write(line)This read from one file and write to another. Basically, it's copying the file.