Forum: Poser Python Scripting


Subject: Useful Code Snippets

structure opened this issue on Jun 27, 2019 ยท 94 posts


structure posted Sun, 08 November 2020 at 10:23 AM Forum Coordinator

convert bytes to kb, mb. gb etc :

class conversions:
    def convert_bytes( self, 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])

Locked Out