Skip to main content

Python alternative (binary) flags

Project description

Python alternative flags

How to install

pip install altflags

How to use

from altflags import Flags, flag

class Permissions(Flags)
    view_page = flag(0)
    add_message = flag(1)

user = Permission()

user.view_page = True

print(user.view_page)
# 

print(user.flags)
# >>> 1

user.add_message = True

print(user.add_message)
# >>> True

print(user.flags)
# >>> 3

user.view_page = False

print(user.view_page)
# >>> False

print(user.flags)
# >>> 2

print("{:0b}".format(user.flags))
# >>> 10

Flag method arguments

The n argument in altflags.flag(n) is the bit position of the flag

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

altflags-0.0.1b0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

altflags-0.0.1b0-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

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