Created
July 14, 2023 00:21
-
-
Save nick3499/60e38b89c3d4cb5789fb72ba67db4796 to your computer and use it in GitHub Desktop.
Word Counter: os.listdir()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
'''Count word total in text file.''' | |
from os import listdir | |
print(listdir()) # optional | |
inp = input('Enter filename: ') | |
with open(inp) as file: | |
text = file.read() | |
replace_mdash = text.replace('—', ' ') | |
split_text = replace_mdash.split() | |
print(f'\x1b[0;31mword count\x1b[0m: {len(split_text)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used this script to count the total number of words in a text file for my flash fiction hobby.
emdashes were replaced with spaces because they caused the word at each end together to be counted as one.
Since then I use gEdit's word count feature.