File objects? - under the hood question

Eric Pederson whereU at now.com
Wed Jan 19 01:53:10 EST 2005


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")

(2)    >>> hesjustsleeping = f.read()

At (1) have I loaded the file from hard drive into RAM when I create the file object?  What does this object know and how did it find it out?

At (2) am I loading the file contents into RAM, or just assigning what is already in RAM to a variable? 

Where is the work split between the OS and Python?  I assume the OS is responsible for "presenting" the file to Python, so perhaps the OS assembles this file from the blocks on disk and loads it into RAM at the time the file object is created?  Or would the OS simply have pointers that can assemble the file, and pass those pointers to Python?

Perhaps I've answered my question and the under-the-hood mechanics are handled on the OS side, and Python is just making requests of the OS...


My brain-teaser:  What I'd like to do is read the last ~2K of a large number of large files on arbitrary servers across the net, without having to read each file from the beginning (which would be slow and resource inefficient)...




Eric Pederson
http://www.songzilla.blogspot.com
:::::::::::::::::::::::::::::::::::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::::::::::::::::::::::::::::::::




More information about the Python-list mailing list