source = open("file1")
out = open("file2", "w")
days = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
for line in source:
out.write(line)
if line.startswith('HERE IS WHERE I WOULD LIKE THE DAYS TO BE LOOPED'):
break
out.close()
source = open(file1) out = open(file2, w) days = [‘Mon’,’Tue’,’Wed’,’Thu’,’Fri’,’Sat’,’Sun’] for line in source:
Share
Looking at
help(str.startswith), you can see that the method accepts a tuple of strings to search for, so you can do it all in one step:Here is a variant that runs on older versions of Python: