filetext filetext replace('$home$'homedirfiletext filetext replace('$file$'filenameopen(fwdname' 'write(filetextcount + insert text and write file varies print('last file =>\ 'filetextsep=''print('done:'count'forward files created 'notice that the template' text is loaded by reading fileit would work just as well to code it as an imported python string variable ( triple-quoted string in module filealso observe that all configuration options are assignments at the top of the scriptnot command-line argumentssince they change so seldomit' convenient to type them just once in the script itself but the main thing worth noticing here is that this script doesn' care what the template file looks like at allit simply performs global substitutions blindly in its textwith different filename value for each generated file in factwe can change the template file any way we like without having to touch the script though fairly simple techniquesuch division of labor can be used in all sorts of contexts--generating "makefiles,form lettershtml replies from cgi scripts on web serversand so on in terms of library toolsthe generator scriptuses os listdir to step through all the filenames in the site' directory (glob glob would work toobut may require stripping directory prefixes from file namesuses the string object' replace method to perform global search-and-replace operations that fill in the $-delimited targets in the template file' textand endswith to skip non-html files ( images--most browsers won' know what to do with html text in jpgfileuses os path join and built-in file objects to write the resulting text out to forward-link file of the same name in an output directory the end result is mirror image of the original website directorycontaining only forward-link files generated from the page template as an added bonusthe generator script can be run on just about any python platform-- can run it on my windows laptop (where ' writing this book)as well as on linux server (where my learning-python com domain is hostedhere it is in action on windowsc:\pp \system\filetoolspython site-forward py creating about-lp html as :\temp\isp-forward\about-lp html creating about-lp html as :\temp\isp-forward\about-lp html creating about-lp html as :\temp\isp-forward\about-lp html creating about-lp html as :\temp\isp-forward\about-lp html creating about-lp html as :\temp\isp-forward\about-lp html many more lines deleted creating training html as :\temp\isp-forward\training html creating whatsnew html as :\temp\isp-forward\whatsnew html generating redirection web pages