<分区>
from glob import glob
from os.path import isfile
def countwords(fp):
with open(fp) as fh:
return len(fh.read().split())
print "There are" ,sum(map(countwords, filter(isfile, glob("*.txt") ) ) ), "words in the files."
在第一行,为什么不直接导入 glob 库?
在“import glob”之前使用“from glob”是否有任何理由?