in places you didn' anticipateyou might just ruin an entire tree of files by running the replacevisitor object defined here on the other handif the string is something very specificthis object can obviate the need to manually edit suspicious files for instancewebsite addresses in html files are likely too specific to show up in other places by chance counting source code lines (visitorthe two preceding visitor module clients were both search-orientedbut it' just as easy to extend the basic walker class for more specific goals example - for instanceextends filevisitor to count the number of lines in program source code files of various types throughout an entire tree the effect is much like calling the visitfile method of this class for each filename returned by the find tool we wrote earlier in this but the oo structure here is arguably more flexible and extensible example - pp \tools\visitor_sloc py ""count lines among all program source files in tree named on the command lineand report totals grouped by file types (extensiona simple sloc (source lines of codemetricskip blank and comment lines if desired ""import syspprintos from visitor import filevisitor class linesbytype(filevisitor)srcexts [define in subclass def __init__(selftrace= )filevisitor __init__(selftrace=traceself srclines self srcfiles self extsums {extdict(files= lines= for ext in self srcextsdef visitsource(selffpathext)if self trace print(os path basename(fpath)lines len(open(fpath'rb'readlines()self srcfiles + self srclines +lines self extsums[ext]['files'+ self extsums[ext]['lines'+lines def visitfile(selffilepath)filevisitor visitfile(selffilepathfor ext in self srcextsif filepath endswith(ext)self visitsource(filepathextbreak class pylines(linesbytype)srcexts [py'pyw'just python files complete system programs