Peter Hansen <[EMAIL PROTECTED]> wrote:
>  >>> from path import path
>  >>> path('foobar').getsize()
> 12345L
> (But note that it's just a nice wrapper around the scattered builtin 
> ways of doing the same thing, in this case the os.stat().st_size 
> approach mentioned above.  That's not a bad thing, though, IMHO.)

Also if the file in question is already open, it can be done like this:

os.fstat(fileobject.fileno()).st_size

This form avoids some race condition scenarious with the file being changed 
between stat and open.

I think file sizes should be used carefully and only for visual reasons. 
For code logic it is almost always better to go the "it's easier to ask 
forgiveness than ask permission" -route. Therefore looking up the file size 
is done only rarely and it is not worthy to be a file-object method.

-- 
Juha-Matti Tapio - fil.yo. - +358-50-5419230
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to