21 lines
573 B
Python
21 lines
573 B
Python
#!/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) |