-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
rgmt
  • 14,120
  • 12
  • 47
  • 66

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
  • 27,965
  • 9
  • 68
  • 73
0

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

Post before in this forum

Community
  • 1
  • 1
am2
  • 370
  • 5
  • 20