I was wondering if someone could tell me the pythonic way to check out the following.
I have a 6 bit binary number and want to check with its decimal values. Using mathe
I would use a decorator to map into a dictionary based dispatch:
_dispatch_table = {}
def dispatch_on(*values):
def dec(f):
_dispatch_table.update((v, f) for v in values)
return f
return dec
@dispatch_on(0, 2, 47)
def one():
foo()
bar()
@dispatch_on(2, 23, 89)
def two():
bar()
baz()
x = some_number
_dispatch_table[x]()