Python For loop range by step with step increments -
i wasn't sure how word this, , it's basic feel idiot. i'm new programming , trying figure out how create text file has header task shows range of loop step , followed multiple tasks have sequential range of header per task. how fit range of loop each sub task doesn't incrementally go up. help.
here's bad code:
#!/usr/bin/python list = [] i, x in enumerate(range(1,15,4)): test = range(x,max(0,min((x+4),16))) list.append(test) foo = """ task -title{%(start)s:%(end)s} %(child)s """ foo2 = """ task -title{%(frame)s} -stuff """ addtask = "" addtask2 = "" in list: first = i[0] last = i[len(i)-1] x in i: frm = foo2 % {"frame":x} addtask2+=(frm) new = foo % {"start":first,"end":last,"child":addtask2} addtask+=(new) f = open("/tmp/test.txt","w") f.write(addtask) f.close()
and below returns:
task -title{1:4} task -title{1} -stuff task -title{2} -stuff task -title{3} -stuff task -title{4} -stuff task -title{5:8} task -title{1} -stuff task -title{2} -stuff task -title{3} -stuff task -title{4} -stuff task -title{5} -stuff task -title{6} -stuff task -title{7} -stuff task -title{8} -stuff task -title{9:12} task -title{1} -stuff task -title{2} -stuff task -title{3} -stuff task -title{4} -stuff task -title{5} -stuff task -title{6} -stuff task -title{7} -stuff task -title{8} -stuff task -title{9} -stuff task -title{10} -stuff task -title{11} -stuff task -title{12} -stuff task -title{13:15} task -title{1} -stuff task -title{2} -stuff task -title{3} -stuff task -title{4} -stuff task -title{5} -stuff task -title{6} -stuff task -title{7} -stuff task -title{8} -stuff task -title{9} -stuff task -title{10} -stuff task -title{11} -stuff task -title{12} -stuff task -title{13} -stuff task -title{14} -stuff task -title{15} -stuff
you forgot reset addtask2
each iteration.
Comments
Post a Comment