-1

i have a loop but its incrementing. what is the syntax for decrementing the loop?

for item2 in textPad.get(itemindex,END):
    tagnames = textPad.tag_names(str(curline)+"."+str(curchar))
    if not "phpsingqoute" in tagnames and not "phpdoubqoute" in tagnames and not "phpcomment" in tagnames:
        if item2 == theopenandclose[1]:
            opencount -= 1
            if opencount == 0:
                textPad.tag_add(tagname,str(curline)+"."+str(curchar))
                textPad.tag_config(tagname,foreground="white",background="#000")
                break
        if item2 == theopenandclose[0]:
            opencount += 1
    if re.match(r'\n',item2):
        curline += 1
        curchar = -1
    curchar += 1
rocambille
  • 15,398
  • 12
  • 50
  • 68

2 Answers2

0

If textPad.get returns a list, you can use reversed

for item2 in reversed(textPad.get(itemindex,END)):

This will also work for some other iterable types, but not all. See the documentation. If you get a TypeError, try converting the result of textPad.get to a list first.:

for item2 in reversed(list(textPad.get(itemindex,END))):
Daniel Hepper
  • 28,981
  • 10
  • 72
  • 75
0

can not add a comment the answer is reversed(...)

Post before in this forum

Community
  • 1
  • 1
am2
  • 380
  • 5
  • 21