File: class/Workbook/Examples/Lecture10/unmore.py
#!/usr/local/bin/python # unpack result of "more x y z > f" # usage: "unmore.py f" or "unmore.py < f" import sys marker = ':'*14 try: input = open(sys.argv[1], "r") except: input = sys.stdin output = sys.stdout while 1: line = input.readline() if not line: # end of file? break elif line[:14] != marker: # text line? output.write(line) else: # file prefix fname = input.readline()[:-1] # strip eoln ('\n') print 'creating', `fname` output = open(fname, "w") # next output line = input.readline() # end of prefix if line[:14] != marker: print "OOPS!"; sys.exit(1) print 'Done.'