Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

This module manages sizes as they are reported by various UNIX commands.

Project description

This module manages sizes of devices like files, block devices or system memory, as they are reported by various UNIX commands. It can be useful for people who often parse command outputs, log file, etc, looking for sizes in various units and formats to compare and compute them, then print results in a homogeneous way.

>>> from Size import mkSize
>>> a = mkSize('20 Gb')         # Default unit is 'm'
>>> b = mkSize('0.1T', 'k')     # Size in kilobytes from string in Tera
>>> a, b
(20480.0, 107374182.40000001)   # a and b are float
>>> a(), b()                    # sizes are callable
('20480 Mb', '107374182 Kb')    # Results in human readable string
>>> c = b - a                   # Sizes may be added or substracted
>>> d = a * 3                   # or divided or multiplied
>>> d.g('%dMBytes')             # Sizes may be converted in differents units
'60GBytes'                      # and printed with differents formats
>>> b.smartprint(6)             # Size may be printed with the smallest unit
'102 Gb'                        # that fills a given length
>>> b.smartprint(10)            #
'104857 Mb'

Project details


Release history Release notifications

This version
History Node

0.1

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page