ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] Question on tell() function and error produced
by Jeff Shannon other posts by this author
Feb 15 2003 2:37AM messages near this date
[Tutor] Question on tell() function and error produced | [Tutor] Python Cookbook
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





_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Henry Steigerwaldt
Jeff Shannon

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved