spark: add Python line counter snippet and verification result
This commit is contained in:
1 parent
0d09e98042
commit
0e8f578bbc
2 files changed
+20
No files matched your search
@@ -0,0 +1 @@
|
||||
9541
|
||||
@@ -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))
|
||||
Reference in new issue
Block a user