file size in python by 바죠

출처: http://www.daniweb.com/forums/thread78629.html
출처: http://snippets.dzone.com/posts/show/5434


>>> import os
>>> b= os.path.getsize("/path/isa_005.mp3")
>>> b
2071611L
>>>>>> import os
>>> b= os.path.getsize("/path/isa_005.mp3")
>>> b
2071611L
>>>

Byte 단위로 출력


------------------------------------------------------------------------------------------
def prettySize(size):
suffixes = [("B",2**10), ("K",2**20), ("M",2**30), ("G",2**40), ("T",2**50)]
for suf, lim in suffixes:
if size > lim:
continue
else:
return round(size/float(lim/2**10),2).__str__()+suf

print prettySize(213458923)
# Output: 203.57M

print prettySize(1234)
# Output: 1.21K

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://incredible.egloos.com/tb/3751025 [도움말]

덧글

덧글 입력 영역