Skip to content

Instantly share code, notes, and snippets.

@Mizzlr
Created October 11, 2018 09:19
Show Gist options
  • Save Mizzlr/fb5d60b49d3e4567c4213110ed5bc842 to your computer and use it in GitHub Desktop.
Save Mizzlr/fb5d60b49d3e4567c4213110ed5bc842 to your computer and use it in GitHub Desktop.
Work frequency in a python codebase.
import tokenize, collections, pathlib, pprint
counter = collections.Counter()
source_path = pathlib.Path('.')
for filename in source_path.glob('**/*.py'):
print(f'Scanning tokens {filename} ...')
tokens = tokenize.tokenize(open(filename, 'rb').__next__)
for token in tokens:
if token.type == 1 or token.type == '3' and ' ' not in token.string:
counter[token.string] += 1
pprint.pprint(counter)
print(f'len: {len(counter)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment