Dougs Sample Python Code

This is Doug's sample python code to do, essentially, what the BASH command in 5x16 did. Email Doug and tell him that you give in, and that BASH is inferiour to Python, or else he'll probably keep sending sample code for as long as I continue to podcast. In fact, email him and tell him that you no longer use BASH, opting instead to log into a python prompt and write custom apps in python to interact with your system. :-P

#!/usr/bin/python

# import library module to read file patterns from directories

import glob

# create and open the output file for writing

outfile = open("toc.ouptut", "w")

# iterate over the files that match "*.txt"

for filename in glob.glob("*.txt"):

[tab] outfile.write(open(filename).readline())

return to main page