출처: 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
출처: 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
태그 : PYTHON




덧글