Get size of movie file in Python
How would I get the size of a .mov file in Python. With other files, I can do:
>>> f = open('<file>')
>>> import os
>>> os.path.getsize(f.read())
However, when I try and do this with a .mov file, I get the following error:
>>> os.path.getsize(f.read())
Traceback (most recent c开发者_如何转开发all last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/genericpath.py", line 49, in getsize
return os.stat(filename).st_size
TypeError: stat() argument 1 must be (encoded string without NULL bytes), not str
What is causing this error and how would I get the filesize?
You are doing it wrong. os.path.getsize
takes a file name, not file contents. I have no idea why your first code sample works.
So you need to call just os.path.getsize(<file>)
.
Try the following:
os.path.getsize(FILENAME_AS_STRING)
精彩评论