I'm trying to complete NaNoWriMo which involves keeping track of your wordcount in order to meet the goal of writing 50,000 words. I've been doing so using a Python script:
import glob
def count_words(ftype):
wordcount = 0
for found_file in glob.glob(ftype):
with open(found_file, 'r') as chapter:
for line in chapter:
if line.strip():
words = line.split(' ')
wordcount += len(words)
return wordcount
>>> count_words('*md')
14696
However, I've just realized that the Bash 'wc' command (which I just learned about) disagrees:
~/nano$ wc *md -w
2656 ch01.md
438 ch02.md
2112 ch03.md
1246 ch04.md
2367 ch05.md
2131 ch06.md
1406 ch07.md
1060 ch08.md
21 rules.md
13437 total
So the total wordcount reported by WC is only 13,437 words.
Dammit, I'm behind! What's going on? LibreOffice and Google Sheets, by the way, agree with bash, so I'm tagging this as a Python question because I'm pretty sure that the problem is with my script.