Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert blocks to mb python

# Input 
#   size - in blocks
# Output
#   size - to the nearest possible unit with 1 decimal precision
#   power label - to indicate if its rounded to Blocks, KB, MB, GB or TB
def format_bytes(size):
    # 2**10 = 1024
    power = 2**10
    n = 0
    power_labels = {0 : 'Blocks', 1: 'KB', 2: 'MB', 3: 'GB', 4: 'TB'}
    while size > power:
        size /= power
        n += 1
    return size, power_labels[n]
Comment

PREVIOUS NEXT
Code Example
Python :: webex teams api attach file 
Python :: python if nan 
Python :: random number list 
Python :: how to format a file in python 
Python :: create database tables python 
Python :: how to hello world in python 
Python :: append numeric number in and auto increment in using pandas 
Python :: python time a task 
Python :: python serial COM3 
Python :: k fold cross validation xgboost python 
Python :: python plot normal distribution 
Python :: gui def python 
Python :: install requests-html with conda 
Python :: embeds discord.py 
Python :: check if value is in list python 
Python :: getting last n rows of column 
Python :: how to set class attributes with kwargs python 
Python :: python split string on char 
Python :: pure imagination 
Python :: get raster corners python 
Python :: python remove multiple element from list by index 
Python :: The MEDIA_URL setting must end with a slash. 
Python :: python remove first element of array 
Python :: import modules given the full path python 
Python :: size pilimage 
Python :: Check instance has an attribute in python 
Python :: python radiobutton default value 
Python :: clear all value in set on python 
Python :: python check if string is float 
Python :: beautiful soup find 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =