The simplest way to create bit-flags
Project description
intflags
Simplest way to create bit-flags.
$ pip install intflags
Usage
Create any number of intflags by using intflags.get()
. You can create a union of any amount using the pipe (|
) operator.
>>> import intflags
>>> a, b, c = intflags.get(3)
>>> bin(a | b | c)
'0b111'
>>> flags = a | b
>>> a in flags
True
>>> c in flags
False
Flags can be subtracted.
# ...
>>> new_flags = flags - b
>>> b in new_flags
False
>>> new_flags == a
True
You could use classes as a pseudo-namespace.
>>> class RegexFlags:
... I, L, M, S, U, X = intflags.get(6)
Flags share an internal "namespace" ID to prevent accidental conflicts between sets. This allows multiple sets of flags to exist within the same class or module, without risk of accidentally creating a union between them.
>>> x = intflags.get(1)
>>> y = intflags.get(1)
>>> x | y
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
ValueError: Flags must share a namespace to create a union.
License
IntFlags is licensed under the ISC license. A copy of the license is included in the root of this repository and in the source of the module.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file intflags-2.0.0.tar.gz
.
File metadata
- Download URL: intflags-2.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.8.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d2a8881402c3e626eea489d260ea9adde75a5c34d6694d151bd18a753aab9e7 |
|
MD5 | 6308bcc86245eccfe4f8ab49e5b144fe |
|
BLAKE2b-256 | b8fedc95c7bae794a74b7bee1516930bde4a76957f0a34d951a5581e6a12c11f |
File details
Details for the file intflags-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: intflags-2.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.3 CPython/3.8.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfcce38fe07af394eb159149d05cf8818cfcb316bfac75ce6d7abc07434041b9 |
|
MD5 | a7af4b4925f516426ff58bfd6058b77a |
|
BLAKE2b-256 | 5deb36374eba3d37bfbaf1cb0c54d2188c6f7b385dbf4de72358eaac2b215597 |