spark: line counter artifact with verification
This commit is contained in:
1 parent
d3a3188c9c
commit
43d1acf4c0
2 files changed
+22
No files matched your search
@@ -0,0 +1 @@
|
||||
18
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Line counter utility - counts non-empty lines in a file."""
|
||||
import sys
|
||||
|
||||
def count_nonempty_lines(filepath):
|
||||
"""Count lines that have content (not just whitespace)."""
|
||||
count = 0
|
||||
with open(filepath, 'r') as f:
|
||||
for line in f:
|
||||
if line.strip():
|
||||
count += 1
|
||||
return count
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python line_counter_artifact.py <file>")
|
||||
sys.exit(1)
|
||||
|
||||
filepath = sys.argv[1]
|
||||
result = count_nonempty_lines(filepath)
|
||||
print(result)
|
||||
Reference in new issue
Block a user