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
Python 统计一个纯英文文件中的单词总个数
最新推荐文章于 2024-02-13 09:35:03 发布