finding file size

John Roth newsgroups at jhrothjr.com
Sat Jan 3 07:46:21 EST 2004


"Martin v. Loewis" <martin at v.loewis.de> wrote in message
news:bt3l9i$pog$07$3 at news.t-online.com...
> Sean Ross wrote:
>
> > My question is this: Is there a reason why file objects could not have a
> > size method or property?
>
> Yes. In Python, file objects belong to the larger category of "file-like
> objects", and not all file-like objects have the inherent notion of a
> size. E.g. what would you think sys.stdin.size should return (which
> actually is a proper file object - not just file-like)?
>
> Other examples include the things returned from os.popen or socket.socket.

I think the issue here is that the abstract concept behind a "file-like
object"
is that of something external that can be opened, read, written to and
closed.
As you say, this does not include the notion of basic implementation: a file
on a file system is a different animal than a network socket, which is
different
from a pipe, etc.

I think we need an object that encapsulates the notion of a file (or
directory)
as a file system object. That object shouldn't support "file-like"
activities:
it should have a method that returns a standard file object to do that.

I like Geritt Holl's filename suggestion as well, but it's not the same
as this suggestion.

John Roth
>
> Regards,
> Martin
>





More information about the Python-list mailing list