file's tell() method appears crazily broken (2.0)

Steve Holden sholden at holdenweb.com
Sun Jan 27 18:41:18 CET 2002


"Bengt Richter" <bokr at oz.net> wrote in message
news:a31cuk$san$0 at 216.39.172.122...
> On Sun, 27 Jan 2002 15:02:00 GMT, "Steve  Holden" <sholden at holdenweb.com>
wrote:
>
> >Sorry if this is an old error, I couldn't find anything on SourceForge.
I'd
> >really like to know if it's repeatable in other environments.
> >
> >I cam across this when the rfc822 library failed reading a file
containing a
> >newsgroup post. Some debugging led me to a really simple program which
> >exhibits the same error:
> >
> >import sys
> >fp = open(sys.argv[1], "r")
> >print "File open at", fp.tell()
>
> I'd guess you need "rb" for tell to work properly on non-unix platforms.
>
Well, duh. The need to open files in binary to use tell() has bitten me in
the ass before, I guess it's true, you can't teach an old dog new tricks.

> Still, an informative error message from tell might be nice if it knows
> what's happening.
>
I agree, though I'm not sure whether tell() can sensibly work this out. The
message could be something like "Programmer finger trouble: tell() should be
used only in binary mode".

Thanks for pointing out the error of my ways.

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list