No project description provided
Project description
dict-logic
Usage
Basic
from dictlogic import Logic
logic = Logic()
result = logic.run({
'sequence': [
{'print': 'hello world!'},
{'set': ['a', 10]},
{'print': ['the value of a is', {'get': 'a'}]},
{'select': [
{'>': [{'get': 'a'}, 5]},
{'print': 'this expression will be evaluated'},
{'print': 'this expression will be ignored'},
]},
{'set': ['a', {'*': [{'get': 'a'}, 2]}]},
{'get': 'a'},
],
})
assert(result == 20)
With given local variabls
from dictlogic import Logic
logic = Logic()
result = logic.run({
'sequence': [
{'print': ['the value of a is', {'get': 'a'}]},
{'set': ['c', {'+': [{'get': 'a'}, {'get': 'b'}]}]},
{'print': ['the value of c is', {'get': 'c'}]},
],
}, {
'a': 5,
'b': 3,
})
With custom functions
from dictlogic import Logic
logic = Logic()
@logic.add('sqrt')
def sqrt(x):
return x() ** 0.5
@logic.add('mean')
def power(*args):
args = [arg() for arg in args]
return sum(args) / len(args)
logic.run({'print': {'sqrt': 2}})
logic.run({'print': {'mean': [1, 2, 3, 4, 5, 6, 7]}})
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
dict-logic-1.0.1.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for dict_logic-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37b7ca9f271b9779b339ef6365ceae5183ce76fe9fe2a1546f11614e167b3253 |
|
MD5 | 2312cad2db33739b608eb0c7f31f4ec0 |
|
BLAKE2b-256 | a6fc7239d5ee2bd515bfd43e989cf2afd896c3eb9c0cdd01676be70179a274ad |