I want all the print's in my text editor to be purple. When I'm coding it, it looks for each occurrence of print in my code, and tries to add a tag to it. Unfortunately, it's giving me an error that unicode strings don't work with it?
def convertToPyTags(self, blah=None):
# Run every time a key is pressed, I know that works
indexes = [] # This works
textdata = self.texteditor.get("1.0",END) # This works
print textdata
print list(textdata), "L" + str(len(textdata)) # This works
for i in len(textdata):
if (textdata[i:(i+7)] == " print "): # This is where it gives an error
indexes.insert(len(indexes), i)
print indexes
""" OUTPUT """
[u'p', u'r', u'i', u'n', u't', u' ', u'"', u'H', u'e', u'l', u'l', u'o', u' ', u'w', u'o', u'r', u'l', u'd', u'!', u'"', u'\n'] L21
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1486, in __call__
return self.func(*args)
File "script", line 145, in keyPress
self.convertToPyTags()
File "script", line 136, in convertToPyTags
for i in len(textdata):
TypeError: 'int' object is not iterable
I don't know what this means - apparently integers aren't iterable?
Again, paste bin