Search

Reading and Writing Files

reading a file and adding it to a list:

months = open('months.txt')

print(months.readlines())
for month in months:
	print(month.strip())

to write to a file add a w:

days = open('days.txt', "w")
days.write("Monday")

to append to a file add a a:

days = open('days.txt', "a")
days.write("Tuesday")