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.2.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file dict-logic-1.0.2.tar.gz
.
File metadata
- Download URL: dict-logic-1.0.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e70b064f6453725190a52d8b5758daf89f6ee566f5c0c565d6fe502c0b267dc5 |
|
MD5 | 99b8c6151f1ba9da69b981c960cad912 |
|
BLAKE2b-256 | 15b61844f4c32c1b9779145113957436142cb0b77c36f7863c61640b100a9689 |
File details
Details for the file dict_logic-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: dict_logic-1.0.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc6ee021baa4d6f2a515986c0202e5dfd5466ab58936813226e86d477fb4fb0e |
|
MD5 | 872111f228e7ce0b0550b1459f567ce1 |
|
BLAKE2b-256 | d2fc852866021c3141571a2181195ea46e74d41a7a6145bf274c07057659e506 |