可能重複:
'import module' or 'from module import'
from … import
vsimport .
我沒有在Python的 '從' 理解
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庫?
是否有任何理由在「導入glob」前使用「from glob」?
也許更好:http://stackoverflow.com/questions/710551/import-module-or-from-module-import – 2012-08-08 13:44:22