I'd like to count the uniqueness of my variable names in all the python code I've written. To do so, I need to strip out all the keywords and reserved words (which are known), the comments and the strings. For example, the following code:
''' long comment '''
for x in range(y, y+foo):
print "Hello", 'world', '''lookout for the # tricky nest''', q # comment
should be stripped to the tokens of for, x, in, range, y, foo, print, q which can be further parsed using a known set of keywords. Is this possible using the python engine itself (maybe with the ast module)?