pretty.py

Go to the documentation of this file.
00001 def prettySize(size):
00002         suffixes = [("B",2**10), ("K",2**20), ("M",2**30), ("G",2**40), ("T",2**50)]
00003         for suf, lim in suffixes:
00004                 if size > lim:
00005                         continue
00006                 else:
00007                         return round(size/float(lim/2**10),2).__str__()+suf
00008 
00009 if (__name__ == '__main__'):
00010         print prettySize(213458923)
00011         # Output: 203.57M
00012         
00013         print prettySize(1234)
00014         # Output: 1.21K
00015 
00016 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...