progressbar.utils module¶
-
progressbar.utils.
format_time
(time, precision=datetime.timedelta(0, 1))[source]¶ Formats timedelta/datetime/seconds
>>> format_time('1') '0:00:01' >>> format_time(1.234) '0:00:01' >>> format_time(1) '0:00:01' >>> format_time(datetime.datetime(2000, 1, 2, 3, 4, 5, 6)) '2000-01-02 03:04:05' >>> format_time(datetime.date(2000, 1, 2)) '2000-01-02' >>> format_time(datetime.timedelta(seconds=3661)) '1:01:01' >>> format_time(None) '--:--:--' >>> format_time(format_time) Traceback (most recent call last): ... TypeError: Unknown type ...
-
progressbar.utils.
get_terminal_size
()[source]¶ Get the current size of your terminal
Multiple returns are not always a good idea, but in this case it greatly simplifies the code so I believe it’s justified. It’s not the prettiest function but that’s never really possible with cross-platform code.
Returns: Two integers containing width and height Return type: width, height
-
progressbar.utils.
scale_1024
(x, n_prefixes)[source]¶ Scale a number down to a suitable size, based on powers of 1024.
Returns the scaled number and the power of 1024 used.
Use to format numbers of bytes to KiB, MiB, etc.
>>> scale_1024(310, 3) (310.0, 0) >>> scale_1024(2048, 3) (2.0, 1) >>> scale_1024(0, 2) (0.0, 0) >>> scale_1024(0.5, 2) (0.5, 0) >>> scale_1024(1, 2) (1.0, 0)
-
progressbar.utils.
timedelta_to_seconds
(delta)[source]¶ Convert a timedelta to seconds with the microseconds as fraction >>> from datetime import timedelta >>> ‘%d’ % timedelta_to_seconds(timedelta(days=1)) ‘86400’ >>> ‘%d’ % timedelta_to_seconds(timedelta(seconds=1)) ‘1’ >>> ‘%.6f’ % timedelta_to_seconds(timedelta(seconds=1, microseconds=1)) ‘1.000001’ >>> ‘%.6f’ % timedelta_to_seconds(timedelta(microseconds=1)) ‘0.000001’