+ for \ added import os info os stat( ' :\temp\spam txt'info nt stat_result(st_mode= st_ino= st_dev= st_nlink= st_uid= st_gid= st_size= st_atime= st_mtime= st_ctime= info st_modeinfo st_size ( via named-tuple item attr names import stat info[stat st_mode]info[stat st_sizevia stat module presets ( stat s_isdir(info st_mode)stat s_isreg(info st_mode(falsetruethe os stat call returns tuple of values (reallyin special kind of tuple with named itemsgiving low-level information about the named fileand the stat module exports constants and functions for querying this information in portable way for instanceindexing an os stat result on offset stat st_size returns the file' sizeand calling stat s_isdir with the mode item from an os stat result checks whether the file is directory as shown earlierthoughboth of these operations are available in the os path moduletooso it' rarely necessary to use os stat except for low-level file queriespath ' :\temp\spam txtos path isdir(path)os path isfile(path)os path getsize(path(falsetrue file scanners before we leave our file tools surveyit' time for something that performs more tangible task and illustrates some of what we've learned so far unlike some shell-tool languagespython doesn' have an implicit file-scanning loop procedurebut it' simple to write general one that we can reuse for all time the module in example - defines general file-scanning routinewhich simply applies passed-in python function to each line in an external file example - pp \system\filetools\scanfile py def scanner(namefunction)file open(name' 'while trueline file readline(if not linebreak function(linefile close(create file object call file methods until end-of-file call function object the scanner function doesn' care what line-processing function is passed inand that accounts for most of its generality--it is happy to apply any single-argument function file and directory tools