O'Reilly logo

Python 2.6 Text Processing Beginner's Guide by Jeff McNeil

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - accessing files directly

Let's update our LogProcessor so that we can pass a file on the command line rather than read all of our data via sys.stdin.

  1. Create a new file named logscan-c.py, using logscan.py as your template. We'll be adding file access support to this original "combined format" processor.
  2. Update the code in the __name__ == '__main__' section as follows.
     if __name__ == '__main__': parser = OptionParser() parser.add_option('-s', '--size', dest="size", help="Maximum File Size Allowed", default=0, type="int") parser.add_option('-f', '--file', dest="file", help="Path to Web Log File", default="-") opts,args = parser.parse_args() call_chain = [] if opts.file == '-': file_stream = sys.stdin else: try: file_stream = open(opts.file, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required