[Tutor] Question on tell() function and error produced
Jeff Shannon
jeff@ccvcorp.com
Fri Feb 14 21:38:04 2003
Henry Steigerwaldt wrote:
>To All:
>
>Can anyone tell me how to use the tell( ) function when
>accessing data on the Web?
>
>I know how to use it when reading a file from the hard drive,
>but I get an error using it after reading text via the Web and
>then trying to use it on that particular "file object."
>
I believe that the file-like object that urllib provides does not
support tell(), nor seek(). This is due to underlying limitations of
using a data stream as a file -- there's no truly meaningful concept of
"position" in a data stream. Similarly, seek() and tell() don't --
can't -- work on sockets.
>I guess I could save the data to a file,
>then open the file and read it, THEN use the tell ( ) (and for that
>matter the seek( ) ) function like I am accustomed to doing
>successfully in the past. But I should be able to use it as is on the
>file object.
>
If you really need seek() and tell(), then you'll have to save the data
to a disk file. Remember, urllib and such don't provide an actual file
object, just a "file-like" object. This is one of the relatively few
ways that it doesn't (can't) completely mimic a true file object. (Of
all file methods, seek() and tell() are the ones most often left
unimplemented in file-like objects, most often because they hold no
meaning to the form of the underlying data that the file-like object is
wrapping.)
Jeff Shannon
Technician/Programmer
Credit International