Re:When being idiomatic wears you out
by krakensden on Saturday August 27, 2011 @01:20PM
(#2931938)
The file protocol is for generic streams, but you could seek to the end and then call tell().
If you just want to know the size of a file and don't want to write to it, os.stat() will do what you want.
Perhaps I'm misunderstanding what you wanted to do, but is there a reason you can't use os.path.getsize?
I digged into python File nonsense trying to find a size() method, and the best explanation I got is that File doesn't have a size() method because it's not meant to designate a file but a strange mix of input/output stream/reader/writer. And since you can't really navigate into python code, I had to google quite a lot to get this explanation.
Best part of the story ? Actually I use django and it has a sane File class with a size() on it, just that it's not appearing in google when you don't send the right request (and IO is pyhton base stuff, not web stuff in my head, so I didn't put the django keyword).