Files

19 lines
696 B
Python

#!/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))