我的情况是,我正在尝试使用page based word count
获得python
。我尝试了下面的代码,现在我可以得到字数统计,但是我正在努力获取基于页面的字数统计。请提供一些建议和代码行。
import os
import os.path
import time
import string
import urllib
def text_file(inF):
num_lines = 0
num_words = 0
num_chars = 0
with open(inF, 'r') as input_file:
for line in input_file:
num_lines += 1
line_words = line.split()
num_words += len(line_words)
for word in line_words:
num_chars += len(word)
file = open(inF, 'r')
print 'File Content: ' + file.read()
print 'File Word: ' + num_words
text_file('Sample.txt')
期望输出:
总页数:2页01:120字页面02:220字