Converters
Collection of tools for converting data.
The module contains the following functions:
to_human_size(n_bytes)- Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc.int_to_roman- Convert an integer to Roman.roman_to_int- Convert to integer from Roman.
int_to_roman(number)
¶
Convert an integer to Roman.
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
Integer. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Roman numeral string. |
Source code in src/xloft/converters/roman.py
roman_to_int(roman)
¶
Convert to integer from Roman.
Examples:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roman
|
str
|
Roman numeral string. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Integer. |
Source code in src/xloft/converters/roman.py
to_human_size(n_bytes)
¶
Converts the number of bytes into a human-readable format.
Examples:
>>> from xloft import to_human_size
>>> to_human_size(200)
200 bytes
>>> to_human_size(1048576)
1 MB
>>> to_human_size(1048575)
1023.999 KB
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_bytes
|
int
|
The number of bytes. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Returns a humanized string: 200 bytes | 1 KB | 1.5 MB etc. |