Entry
What is File-like Object?
Sep 2nd, 2000 02:19
unknown unknown, Pete Shinners, Will Ware
a file-like object is any object (including the regular file object)
that has the same methods as the file object. this would typically
be the .read() and/or .write() methods.
The reason many modules mention they take a file-like object is
to give the developer more flexibility. Instead of only taking
a file object, they can take any python object with the same set
of methods.
Most of the time you will probably just use a regular file object.
but you can also use many other objects if you want. usual suspects
would be stuff like sys.stdout, stringio, and similar things
(actually, sys.stdout really is a file object)
hopefully that's not too confusing. if you're still not sure,
just use a regular file object and don't sweat it.
(not sure as to your newbie-ness, a file object is returned
from the open() command) :]
------------------
It's an object that behaves like a file. That is to say,
it implements the methods a file would normally have, such as
read(), readline(), readlines(), write(), flush(), and so forth.
You can find out more about files and their methods in the Python
Tutorial at http://www.python.org/doc/current/tut/tut.html
The part about files is section 7.2.