diff --git a/wizard-work/spark/line_counter_result.txt b/wizard-work/spark/line_counter_result.txt new file mode 100644 index 0000000..5aec5fa --- /dev/null +++ b/wizard-work/spark/line_counter_result.txt @@ -0,0 +1 @@ +9541 \ No newline at end of file diff --git a/wizard-work/spark/line_counter_snippet.py b/wizard-work/spark/line_counter_snippet.py new file mode 100644 index 0000000..919f651 --- /dev/null +++ b/wizard-work/spark/line_counter_snippet.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +"""Count lines of Python in a directory - verifiable snippet.""" +import os +import sys + +def count_python_lines(directory: str) -> int: + """Return total lines of Python code in .py files under directory.""" + total = 0 + for root, _, files in os.walk(directory): + for f in files: + if f.endswith('.py'): + path = os.path.join(root, f) + with open(path, 'r', errors='ignore') as fh: + total += sum(1 for line in fh if line.strip() and not line.strip().startswith('#')) + return total + +if __name__ == '__main__': + target = sys.argv[1] if len(sys.argv) > 1 else '.' + print(count_python_lines(target)) \ No newline at end of file