Trouble with script for deleting hints

I made a new master by copying another, in which I (unfortunately) had already done a lot of TT hinting. Now I’d like to delete the TT hints in the new master. The new master is the fourth layer, so index 3. I’ve tried this:

for g in Glyphs.font.glyphs:
#	print g
	for h in g.layers[3].hints:
#		print h
		del(h)
print "done"

(The print statements are there so I could make sure I was actually hitting the hints.) However, the hints are still there. What am I doing wrong? (This is my first attempt at a script, so please be gentle!)

  1. You cannot remove items from or add to a list while you are iterating over it.
  2. You need to del directly out of the list, like: del layer.hints[i]

What I usually do is get the index numbers, then step backwards through it, to avoid confusion of index numbers after deletion:

for i in range(len(layer.hints)-1, -1, -1):
    del layer.hints[i]

But if you want to delete all hints indiscriminately, you can simply set layer.hints=None. Careful though, that also deletes corner and cap components, which are technically hints.

Thanks very much! Now that you mention it, it’s obvious why I can’t alter a list while iterating over it.

That last (layer.hints=None) is perfect, since I’ve decomposed all my corner and cap components.

Just ran the revised script, and it worked perfectly. Thanks again!