Very stupid question.

Peter Hansen peter at
Thu Mar 30 20:39:40 CEST 2006

On 3/30/06, *Sullivan Zheng* <sullivanz.pku at
<mailto:sullivanz.pku at>> 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 module (Google 
for it) to be more elegant.  With it, this works fine:

 >>> from path import path
 >>> path('foobar').getsize()

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


More information about the Python-list mailing list