您的位置:首页 > 编程语言 > Python开发

Python 统计一个纯英文文件中的单词总个数

2014-11-01 23:29 627 查看
import sys
import string 

if len(sys.argv) == 1 or sys.argv[1] in {"-h","--help"}:
	print ("usage: countWord.py filename_1 filename_2 ... finename_n")
	sys.exit()
else:
	count = 0
	strip = string.whitespace + string.punctuation + string.digits
	for filename in sys.argv[1:]:
		for line in open(filename):
			for word in line.split():
				word = word.strip(strip)
				count += 1

	print("the count of the file is {0} ...".format(count))
参考人家的,自己写了,使用在命令行: pyhton codefilename.py filename_1 filename_2 .... filename_n
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐