Answers for "python file size in mb"

2

python get file size in mb

import os
os.path.getsize("path/to/file") / (1024*1024)
Posted by: Guest on February-26-2021
0

python calculator file size to megabytes

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])
Posted by: Guest on August-22-2020

Code answers related to "python file size in mb"

Python Answers by Framework

Browse Popular Code Answers by Language