Created
September 10, 2020 16:37
-
-
Save EricSchles/f86b874c3840a6619aff0c5752c114c0 to your computer and use it in GitHub Desktop.
count the number of lines in your jupyter notebooks
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
| from glob import glob | |
| from json import load | |
| def loc(nb): | |
| cells = load(open(nb))["cells"] | |
| return sum(len(c["source"]) for c in cells) | |
| root_folder = "~" | |
| summation = 0 | |
| for File in glob(root_folder+"/**/*.ipynb", recursive=True): | |
| summation += loc(File) | |
| print(summation) |
Author
Nice! This is a pretty neat way to do this as well :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks very much for this useful way to count the number of code line in Jupyter notebooks. The version below uses the glob method of pathlib Path objects to list files. It prints the number of lines for each files in the directory and the total number as well.