File: class/Workbook/Examples/Lecture10/unmore3.py
#!/usr/local/bin/python # unpack result of "more x y z > f" # usage: "unmore3.py -i f -v?" or "unmore3.py -v? < f" # uses StreamApp class from "Programming Python" (append D) from apptools import StreamApp marker = ':'*14 class UnmoreApp(StreamApp): # app subclass def run(self): # start/run/stop while 1: line = self.readline() if not line: # end of file? break elif line[:14] != marker: # text line? self.write(line) else: # file prefix fname = self.readline()[:-1] self.message('creating ' + `fname`) self.setOutput(fname) if self.readline()[:14] != marker: self.exit("OOPS!") if __name__ == '__main__': UnmoreApp().main() # make/run