Created
May 1, 2016 20:45
-
-
Save FGFW/94cb898eee286f1d670ebaa369f8bb22 to your computer and use it in GitHub Desktop.
python统计文本字符数量.py
This file contains hidden or 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
| """ | |
| 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