Does move file pointer automatically?

John Machin sjmachin at
Thu Feb 5 03:45:51 CET 2009

On Feb 5, 9:51 am, Lionel < at> wrote:
> Hello everyone. Quick question: When using the "read()" method in the
> array module, must I redirect the current file pointer or will that
> occur automatically?
> For example, if I were to sequentially read data in chunks from a
> binary file as in:
> for currentChunk in range(numberOfChunksToRead):
>        floatData = array.array('f')
>, numberOfFloatsPerChunk)
>        ...go to work on data...
> at each iteration of the "for" loop, will the next chunk of bytes be
> read into "floatData" or must I move the file pointer by calling "seek
> ()" or some function like that?

Suggestions for the the next time you have a question like that:

(1) Consider which outcome is more plausible, write your code
accordingly and see what happens

(2) If it blows up, or if you like looking before you leap anyway, try
inserting temporarily some code -- in this case
  print MyFileHandle.tell()
that will tell you the answer to your question.

In this game you are allowed to experiment to get an answer, and it's
often faster than phone-a-friend :-)

More information about the Python-list mailing list