4 ms·
I actually had the converse experience yesterday. I digged into python File nonsense trying to find a size() method, and the best explanation I got is that Fil
by nraynaud 15y ago
I actually had the converse experience yesterday.
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).
- krakensden 15y agoThe 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.
- clownz0r 15y agoPerhaps I'm misunderstanding what you wanted to do, but is there a reason you can't use os.path.getsize? http://docs.python.org/library/os.path.html#os.path.getsize http://docs.python.org/library/os.path.html#os.path.getsize