Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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])
Comment

PREVIOUS NEXT
Code Example
Python :: getenv python 
Python :: laplace transform python 
Python :: itertools .cycle() 
Python :: generate random int python 
Python :: python enum advanced 
Python :: how to select top 5 in every group pandas 
Python :: python create dummy dataframe 
Python :: scikit learn train test split 
Python :: select python 
Python :: pytest teardown method 
Python :: pandas dataframe get first n rows 
Python :: python string cut last n characters 
Python :: python if null 
Python :: python help 
Python :: Filter with List Comprehension 
Python :: python 2.7 datetime to timestamp 
Python :: how to copy content of one file to another in python 
Python :: logical operators pandas 
Python :: double variable for loop python 
Python :: how to find lcm of 2 numbers in python 
Python :: how to get python list length 
Python :: how to make text to speech in python 
Python :: python casting 
Python :: list in list python 
Python :: python generate set of random numbers 
Python :: find commonalities in dictionary python 
Python :: how to detect the reaction to a message discord.py 
Python :: pandas apply check for string length in column 
Python :: sub matrix python 
Python :: delete outliers in pandas 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =