Very stupid question.

Peter Hansen peter at engcorp.com
Thu Mar 30 13:39:40 EST 2006


On 3/30/06, *Sullivan Zheng* <sullivanz.pku at gmail.com
<mailto:sullivanz.pku at gmail.com>> wrote:
> 
>     Wow, seems I am not that supid. Why python does not include this
>     function in the file object. It is almost a tradition in other
>     languages...
>      
>     import os
>      
>     os.stat(path).st_size
>      
>     really not elegant or OO.

You might find something like Jason Orendorff's path.py module (Google 
for it) to be more elegant.  With it, this works fine:

 >>> 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.)

-Peter




More information about the Python-list mailing list