Skip to content

Instantly share code, notes, and snippets.

@FGFW
Created May 1, 2016 20:45
Show Gist options
  • Select an option

  • Save FGFW/94cb898eee286f1d670ebaa369f8bb22 to your computer and use it in GitHub Desktop.

Select an option

Save FGFW/94cb898eee286f1d670ebaa369f8bb22 to your computer and use it in GitHub Desktop.
python统计文本字符数量.py
"""
python统计文本字符数量.py
2016年5月2日 04:21:44 codegay
http://bbs.bathome.net/thread-40285-1-1.html
"""
import sys
import os
if sys.argv.__len__()<2:
print("参数不能为空!")
print("使用方法:把文件拖到本程序上,或者在终端中执行:\n",sys.argv[0]+" 需要统计的文件名")
exit()
if not os.path.exists(sys.argv[1]):
print("找不到目标文件")
with open(sys.argv[1]) as f:
result=sum([''.join(r.split()).__len__() for r in f])
print(sys.argv[1],"字符数:",result)
input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment