Question : python get file size in mb
Answered by : kostas-minaidis
import os
os.path.getsize("path/to/file") / (1024*1024)
Source : | Last Update : Fri, 05 Mar 21
Question : python calculator file size to megabytes
Answered by : dead-dog-7111ztpktlq2
import math
def convert_size(size_bytes): if size_bytes == 0: return "0B" size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") i = int(math.floor(math.log(size_bytes, 1024))) p = math.pow(1024, i) s = round(size_bytes / p, 2) return "%s %s" % (s, size_name[i])
Source : https://stackoverflow.com/questions/5194057/better-way-to-convert-file-sizes-in-python | Last Update : Sat, 29 Aug 20