def writer(f): for str in f: print "Boo!" (tmp, f2) = os.popen2("ls -l %s" % (str, )) (f3, fout) = os.popen2("awk '{print $5}'") for str2 in f2: print "Boo2!" f3.write(str2) for str3 in fout: print "Boo3!" f.write(str3)