Skip to main content

An enhancement of str.isnumeric()

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

numerical

Python library I made to learn regex and to have a better version of str.isnumeric()

Uploading to PyPI was a horrible experience and they 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.

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}))

This will print True, since the ALLOW flags do not require, they only allow.

A known "issue" with the library is that numbers like 01 will be recognized, but something like int() will strip the leading zero anyway.

I've copied this from the docstring(?) of the function, since it describes basically everything you need to know:

This function uses a "flag" system to control what's allowed and what isn't.
You can pass these in a set called "flags" in the arguments.
The flags are in variables, but you can also use their string values.
1: NM_RETURN_MATCH - Set to the string "RM", this flag makes the function return the raw output of the match function.
2: NM_ALLOW_NEGATIVE - Set to the string "AN" and enabled by default, this flag allows negative numbers.
3: NM_ALLOW_DECIMALS - Set to the string "AD", this flag allows numbers with decimals.

If you want no flags, try passing the result of set()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

better_is_numeric-1.0.5.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

better_is_numeric-1.0.5-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file better_is_numeric-1.0.5.tar.gz.

File metadata

  • Download URL: better_is_numeric-1.0.5.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for better_is_numeric-1.0.5.tar.gz
Algorithm Hash digest
SHA256 a7f06785873238228f3fc5e9fb732ffd07d1a6e5239d50257e0ed6a585b25ed5
MD5 c7e949f93811222a8688a81aa919ead9
BLAKE2b-256 3641cc464214750e09b6c55b12b8228a8e78ddece6989162c41f9b7342e70db3

See more details on using hashes here.

File details

Details for the file better_is_numeric-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for better_is_numeric-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e88d8779697d7e2c980438964649862e12e8d8b2d2ead9d5afe1f92b4fcf52b5
MD5 3ccbb95950149d4d6fc9c6d9bc915789
BLAKE2b-256 7ad883664f911c5920febfebbf193dd0f63137e6879d45e67153b4acc1e4f8cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page