8000 GitHub - bepetersn/flags: Allows you to represent an unknown number of items as a single code--an alternative to *args and **kwargs (see the API) in some situations where it is simple information and not data structures that need to be passed
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allows you to represent an unknown number of items as a single code--an alternative to *args and **kwargs (see the API) in some situations where it is simple information and not data structures that need to be passed

Notifications You must be signed in to change notification settings

bepetersn/flags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Use this module to easily parse a single, unique code containing as much information as your function or program needs, much as the bash 'chmod' command extracts 3 different file permissions from each number in 775.

Code Flags
1 [0]
2 [1]
3 [0, 1]
4 [2]
5 [0, 2]
6 [1, 2]
7 [0, 1, 2]
8 [3]
9 [0, 3]

... and so on. This system relies on the fact that any integer can be broken down into a unique set of the members of the sequence y = 2^n. Basically, these are the members of the base-2 number system which can be represented with just a single digit set, which is to say they are capable of holding the most information.

Usage

Outside of a programmatic interface, call for example:

from flags import code

# set some constants
PRINT = 0
MODIFY = 1
EXTRACT = 2
ANNOTATE = 3
ACCESSIBILITY = 4

some_api(doc, code([PRINT, ANNOTATE, ACCESSIBILITY]))

... specifying an arbitrary number of desired behaviors. Inside that inferface, call:

from flags import flags

def some_api(doc, code):
    # code == 25
    behaviors = flags(code)

    # can't modify
    if MODIFY in behaviors:
        change_stuff(doc)

    # can print
    if PRINT in behaviors:
        queue_print(doc)

... and retrieve the list of integers, each representing a single behavior. Then do something with all that power!

About

Allows you to represent an unknown number of items as a single code--an alternative to *args and **kwargs (see the API) in some situations where it is simple information and not data structures that need to be passed

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0