File objects? - under the hood question

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


On Tue, 18 Jan 2005 22:53:10 -0800, Eric Pederson <whereU at now.com> 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
error.

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

Regards,
Stephen Thorne.



More information about the Python-list mailing list