我正在研究第6章中Mark Pilgrim的Dive Into
Python Book的模块,我对这行代码返回[fileList中的f]的getFileInfoClass(f)(f)的确如此. getFileInfo是一个嵌套函数,我想知道什么是重复(f),额外的括号是.我希望有人可以帮助我.这是完整的功能:
def listDirectory(directory,fileExtList): "get list of file info objects for files of particular extensions" fileList = [os.path.normcase(f) for f in os.listdir(directory)] fileList = [os.path.join(directory,f) for f in fileList \ if os.path.splitext(f)[1] in fileExtList] def getFileInfoClass(filename,module=sys.modules[FileInfo.__module__]): "get file info class from filename extension" subclass = "%sFileInfo" % os.path.splitext(filename)[1].upper()[1:] return hasattr(module,subclass) and getattr(module,subclass) or FileInfo return [getFileInfoClass(f)(f) for f in fileList]