spark: add text_stats.py utility for counting lines/words/chars in text files
This commit is contained in:
1 parent
397cae919d
commit
1c6f3ade0b
1 file changed
+1
-1
@@ -10,7 +10,7 @@ def analyze_text(filepath):
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
|
||||
content = f.read()
|
||||
lines = len(content.splitlines())
|
||||
lines = content.count('\n')
|
||||
words = len(content.split())
|
||||
chars = len(content)
|
||||
return lines, words, chars
|
||||
|
||||
Reference in new issue
Block a user