A Python package for counting Chinese characters in text files.
pip install wccn
Or install from source:
git clone https://github.com/fpGHwd/wccn.git
cd wccn
pip install -e .
# After installation
wccn.py ~/Documents/org 3 .org
# Or using the original script
python wccn.py ~/Documents/org 3 .org
from chinese_wordcount.counter import count_file, walk
# Count Chinese characters in a file
count = count_file('path/to/your/file.txt')
print(f"Chinese character count: {count}")
# Walk through directories
for directory, subdirs, files in walk('path/to/directory', depth=3):
for file in files:
if file.endswith('.txt'):
full_path = f"{directory}/{file}"
count = count_file(full_path)
print(f"{count}\t{full_path}")
MIT
- Description:
- 统计文档中的中文字数,默认 utf-8 编码
- count all chinese characters in a directory with specific file extension appendix and specific depth of search
- Usage:
- =python chinese_wc.py [directory] [depth] [file extension appendix]=
- Example:
- =python chinese_wc.py "/home/wd/Documents/org" 4 ".org"=
- =python chinese_wc.py ~/Documents/org 4 '.org'=