Created
October 11, 2018 09:19
-
-
Save Mizzlr/fb5d60b49d3e4567c4213110ed5bc842 to your computer and use it in GitHub Desktop.
Work frequency in a python codebase.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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