zoukankan      html  css  js  c++  java
  • Python脚本

    测试系统为:Centos 6.7

    Python版本为: 3.6.4

    脚本功能:常用单位的转换,这里用内存来模拟

    import pstuil
    
    def bytes2human(n):
          symbols = ('K','M','G','T','P','E','Z','Y')
          prefix = {}
          for i,s in enumerate(symbols):
              prefix[s] = 1 << (i + 1) * 10
          for s in reversed(symbols):
              if n >= prefix[s]:
                  value = float(n) / prefix[s]
                  return '%.1f%s' % (value,s)
          return '%sB' % n
     
    if __name__ == '__main__':
    	bytes2human(psutil.virtual_memory().total)
    

      

  • 相关阅读:
    iOS数据持久化的方式
    Runtime
    <02>
    <01>
    <02>
    UIActivityIndicatorView
    <01>数据存储
    UI<10>
    UI<09>
    UI<08>
  • 原文地址:https://www.cnblogs.com/dachenzi/p/8232861.html
Copyright © 2011-2022 走看看