On 07/17/2011 03:47 AM, Xah Lee wrote:
2011-07-16

I gave it a shot. It doesn't do any of the Unicode delims, because let's face it, Unicode is for goobers.


import sys, os

pairs = {'}':'{', ')':'(', ']':'[', '"':'"', "'":"'", '>':'<'}
valid = set( v for pair in pairs.items() for v in pair )

for dirpath, dirnames, filenames in os.walk(sys.argv[1]):
    for name in filenames:
        stack = [' ']
        with open(os.path.join(dirpath, name), 'rb') as f:
            chars = (c for line in f for c in line if c in valid)
            for c in chars:
                if c in pairs and stack[-1] == pairs[c]:
                    stack.pop()
                else:
                    stack.append(c)
        print ("Good" if len(stack) == 1 else "Bad") + ': %s' % name

--
Bill
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to