[Pythonmac-SIG] Reading big text files

Pieter Claerhout Pieter Claerhout" <chill@mediaport.org
Tue, 8 Jun 1999 17:59:09 +0200


I tried to make a script that reads a PostScript file line by line, and this
to find the first line which starts with "%%Pages: ". After the program
found this line, is OK to close the file and to print this line.

Everything works fine, but with big files (more than 5 MB, and most of my
PostScript files are bigger than that), I run into memory problems. This is
the source of my script:

 import macfs
 import sys
 import EasyDialogs

 fsspec, ok = macfs.PromptGetFile('File to check end-of-lines in:', 'TEXT')
 if not ok:
  sys.exit(0)

 pathname = fsspec.as_pathname()
 fp = open(pathname, 'r')

 for x in fp.readlines():
  if x[:9] == "%%Pages: ":
   print "Found", x[9:-1], "pages!"
   break

 fp.close()

Anyone an idea how I can handle this problem. I also have some problems with
the different line-ending style from the different platforms. How should I
handle this??

If anyone has another solution for finding the number of pages in a
PostScript file, I am glad to learn from you...

Kind regards,


Pieter

[ Pieter Claerhout
  chill@mediaport.org ]

[ Pieter Claerhout
  chill@mediaport.org ]