Seek and Read Quickly With the os Module
Tuesday May 6, 2008
Some protocols communicate data in forms that are less than
human-friendly. Unlike XML, some communication protocols as well as
older data formats can be downright obtuse. It is not unheard of for some to require the
appending of a certain number of signature characters to a particular
point of a data packet, usually the beginning or the end. While jobs
involving these formats typically include building a parser, if one is
not already built, the efficiency with which the packet is parsed
inevitably reflects on you. Rather than read the file in
toto, it may be worth considering a partial read. To affect this
efficiently, use Python's
os functions lseek()
and read(). To learn how, see "lseek() and ye can
read()", the latest segment in the series on the os module.
