num2alpha
Description
This Python script converts any base-10 integer into its "alphabetical number" counterpart. For example, 1 is a, 26 is z, and 28 is ab. This alphabetical number order is exactly what you find in the column name of most modern spreadsheet apps.
This script can also decode an alphabetical number and return its integer order in base-10. For instance, the spreadsheet column AXY is counted as the 1325-th column of the spreadsheed, and the string helloworld equals to 44580442473324.
Dependencies
This project depends on no third-party/external Python module. All modules required by num2alpha are already provided by the Python Standard Library.
Installation
num2alpha is available for download through Python Package Index (PyPI). Run the following command in your operating system via the terminal:
python -m pip install num2alpha
Usage
Import the num2alpha module as you would other modules.
import num2alpha as n2a
Then you can convert alphabet sequences to their respective numerical order in base-10 using the function alpha_to_number(). This function is case-insensitive. Therefore, alpha_to_number('abc') will yield the same result as alpha_to_number('ABC') as well as alpha_to_number('aBc').
n2a.alpha_to_number('a')
# returns 1
n2a.alpha_to_number('z')
# returns 26
n2a.alpha_to_number('aa')
# returns 27
n2a.alpha_to_number('ab')
# returns 28
n2a.alpha_to_number('python')
# returns 201883748
To do the otherwise, i.e., converting numbers to their respective alphabet forms, use the function number_to_alpha(). Please only pass base-10 integers greater than 0 into it. If you pass a floating number or other non-integer types into it, TypeError will be raised.
The return string will be in the form of [a-z] (in lowercase).
n2a.number_to_alpha(1)
# returns 'a'
n2a.number_to_alpha(2)
# returns 'b'
n2a.number_to_alpha(26)
# returns 'z'
n2a.number_to_alpha(27)
# returns 'aa'
n2a.number_to_alpha(2025)
# returns 'byw'
n2a.number_to_alpha(1234567890)
# returns 'cywoqvj'
If you are unsure about the type of data you are dealing with, you can use autoconvert() function to automatically determine whether the variable passed is a string of alphabetical characters or a base-10 integer. This function will then convert the passed argument accordingly.
n2a.autoconvert(123)
# returns 'ds'
n2a.autoconvert('helloworld')
# returns 44580442473324
Metadata
Release files for num2alpha 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| num2alpha-1.0.1.tar.gz | 31.6 kB | Without provenance | Details for num2alpha-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| num2alpha-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for num2alpha-1.0.1-py3-none-any.whl |
Total release size: 61.4 kB
Release files / num2alpha-1.0.1.tar.gz
| Download URL | num2alpha-1.0.1.tar.gz |
|---|---|
| Size | 31.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb295c44f302441daf47bfd115c431693ba00cd09987b0ede4dc80e93def04e9
|
|
BLAKE2b-256 checksum How to use checksums |
c5ab2ce8986687906df439a95c0efd86d80e195d6af9003f9a7131f26e5b9323
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.7
|
Release files / num2alpha-1.0.1-py3-none-any.whl
| Download URL | num2alpha-1.0.1-py3-none-any.whl |
|---|---|
| Size | 29.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81a87c434a7878db9239be20e44dd2ab5dc57c4d2a013d5b782391d51d649a09
|
|
BLAKE2b-256 checksum How to use checksums |
04caa06cfe77445bd656921230ef8c0c8629e614b8335e58d8c6fc4045de8992
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.7
|
Security for num2alpha 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.