k3num
Convert number to human readable format in a string.
k3num is a component of pykit3 project: a python3 toolkit set.
k3num convert numbers(or numbers in dict or list) to human readable
format in string::
>>> readable(103425)
'101.0K'
>>> readable({ 'total': 10240, 'progress': [1, 1024*2.1, 1024*3.2], })
{'total': '10K', 'progress': ['1', '2.10K', '3.20K']}
>>> parsenum('5.2K')
5324.8
>>> parsenum('10%')
0.1
Attributes:
value_to_unit(dict): map of int to unit, e.g.: 1024 -> "K", 1024² -> "M".
Usage::
>>> value_to_unit[1024**2]
'M'
>>> unit_to_value['K']
1024
unit_to_value(dict): reverse map of `value_to_unit`.
k3num.Hex provides hex integer with arithmatic support.
Different ways to create a 4-byte crc32 hex str::
>>> Hex(0x0102, 4)
'00000102'
>>> Hex(0x0102, 'crc32')
'00000102'
>>> Hex.crc32(0x0102)
'00000102'
>>> Hex('00000102', 'crc32')
'00000102'
>>> Hex.crc32('00000102')
'00000102'
Create with a tuple of prefix and a filling byte::
>>> Hex(('12', 1), 'crc32')
'12010101'
Arithmetic operations::
>>> Hex(0x0102, 'crc32') + 1
'00000103'
>>> Hex(0x0102, 'crc32') * 2
'00000204'
>>> Hex(0x0102, 'crc32') - 1000000
'00000000'
>>> Hex(0x0102, 'crc32') * 1000000000
'ffffffff'
Iterate over sha1 space with a specific step::
>>> Hex.sha1(0) + Hex.sha1(('10', 0))
'1000000000000000000000000000000000000000'
>>> Hex.sha1(0) + Hex.sha1(('10', 0)) * 2
'2000000000000000000000000000000000000000'
Install
pip install k3num
Synopsis
>>> readable(103425)
'101.0K'
>>> readable({ 'total': 10240, 'progress': [1, 1024*2.1, 1024*3.2], })
{'total': '10K', 'progress': ['1', '2.10K', '3.20K']}
>>> parsenum('5.2K')
5324.8
>>> parsenum('10%')
0.1
>>> value_to_unit[1024**2]
'M'
>>> unit_to_value['K']
1024
>>> Hex(0x0102, 4)
'00000102'
>>> Hex(0x0102, 'crc32')
'00000102'
>>> Hex.crc32(0x0102)
'00000102'
>>> Hex('00000102', 'crc32')
'00000102'
>>> Hex.crc32('00000102')
'00000102'
>>> Hex(('12', 1), 'crc32')
'12010101'
>>> Hex(0x0102, 'crc32') + 1
'00000103'
>>> Hex(0x0102, 'crc32') * 2
'00000204'
>>> Hex(0x0102, 'crc32') - 1000000
'00000000'
>>> Hex(0x0102, 'crc32') * 1000000000
'ffffffff'
>>> Hex.sha1(0) + Hex.sha1(('10', 0))
'1000000000000000000000000000000000000000'
>>> Hex.sha1(0) + Hex.sha1(('10', 0)) * 2
'2000000000000000000000000000000000000000'
Author
Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Metadata
Release files for k3num 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| k3num-0.1.12.tar.gz | 9.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3num-0.1.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.0 kB
Release files / k3num-0.1.12.tar.gz
| Download URL | k3num-0.1.12.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eee0c50a39f2e664b033fb2ecb680f266167a4f1f121caf00ab08bfb7715ee47
|
|
BLAKE2b-256 checksum How to use checksums |
1beb9be7237071a2098373dcf0029deb7d26ddd8c025750a5838f68a39041c20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / k3num-0.1.12-py3-none-any.whl
| Download URL | k3num-0.1.12-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a9dcb2a4602481d799f4522a312d4d7de9f67352db98d3bfcd29bb3baee212e
|
|
BLAKE2b-256 checksum How to use checksums |
4cf1fd89229d3f43ff7434c1c48bb6d0427a1035154076a1f65e75d4037fe695
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|