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."
in the first line, why don’t this just simply import glob library?
Is there any reason for using “from glob” in front of “import glob”?
If you write
import glob, you would need to useglob.glob.from glob import globtakesglob.globand makes it available as justglob.