This project has been archived by its maintainers, and is no longer receiving any updates.
numerical
Python library I made to learn regex and to have a better version of str.isnumeric()
PyPI rejected the name without telling me why (too similar to numerics?), so its called better-is-numeric there.
Supports decimals and negative numbers, managed by flags.
Even if you don't need to support decimals or negative numbers, this is still better than str.isnumeric(), since that function for some reason counts exponents (⅐, for example) as numeric.
Should work down to Python 3.9.
Importing is kind of ugly, maybe I'll fix it one day. In the meantime, you can avoid this and the PyPI name by just downloading the code from the Codeberg repository and putting it in the same directory as your program, for a simple from numerical import *
Here's some example code:
from is_numeric.numerical import *
print(is_numeric("1", NM_ALLOW_NEGATIVE, NM_ALLOW_DECIMALS, NM_ALLOW_LEADING_ZERO))
This will print True, since the NM_ALLOW flags do not require, they only allow. If you want to REQUIRE a negative number or decimals, simply check:
if "-" in whatever_string_you_are_checking
if "." in whatever_string_you_are_checking
I've copied this from the docstring(?) of the function, since it describes the flags:
This function uses a "flag" system to control what's allowed and what isn't.
You can pass these as individual arguments, you don't need a list or set or anything.
Certain flags switch the function to dictionary output, to include whatever data you requested.
The simple boolean output is still included in the dictionary output, in the "numeric" field.
The flags are in variables, but you can also use their string values.
1: NM_ALLOW_NEGATIVE - Set to the string "AN", this flag allows negative numbers.
2: NM_ALLOW_DECIMALS - Set to the string "AD", this flag allows numbers with decimals.
3: NM_ALLOW_LEADING_ZERO - Set to the string "AZ", this flag allows "invalid" numbers like 01.
4: NM_ALLOW_PLUS_SIGN - Set to the string "AP", this flag allows explicitly positive numbers, such as +2.
5: NM_RETURN_REGEX - Set to the string "RX", this flag uses dictionary output and returns the constructed regex inside the "regex" field.
If you want no flags, just don't give any.
That is, JUST give the string. is_numeric(string)
Metadata
Release files for better-is-numeric 2.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 | |
|---|---|---|---|
| better_is_numeric-2.0.1.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| better_is_numeric-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / better_is_numeric-2.0.1.tar.gz
| Download URL | better_is_numeric-2.0.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14289c77cfcc7ebd663d96141a65ca47c3970f07d43b145a8a2cf06779cea353
|
|
BLAKE2b-256 checksum How to use checksums |
0e786a419a4d7e9cc661e9aefabb3a0ff45ec99942c250d76dedb4ba81ce30ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|
Release files / better_is_numeric-2.0.1-py3-none-any.whl
| Download URL | better_is_numeric-2.0.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
816152a7b7ea2bf70398dbf54ec62af63f610148af791d3eea09e72df82d4ed3
|
|
BLAKE2b-256 checksum How to use checksums |
e5cb4b421c9ee4db16449ad064bf105473c72dd5c37b4c754cc690445041874d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|