File objects? - under the hood question

Stephen Thorne stephen.thorne at
Wed Jan 19 02:06:29 EST 2005

On Tue, 18 Jan 2005 22:53:10 -0800, Eric Pederson <whereU at> wrote:
> I didn't come across any illuminating discussion via Google, thus my question here (though it may be a neophyte question.) I am interested in the workings under the hood of Python's access of "files".
> What is actually happening at the various stages when I create a file object and "read" it?
> (1)    >>> f = file("C:/GuidosParrot.txt","r")
You've just opened a file for reading. You haven't read any data, but
at this point if the file wasn't there, the OS would have throw you an

> (2)    >>> hesjustsleeping =
The entire file is read directly into a single python str.

Stephen Thorne.

More information about the Python-list mailing list