You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 20, 2021. It is now read-only.
This is the place where you can find what you want to know about PyOPM.
Installation
To get started with PyOPM, you can install it via pip:
$ pip3 install -U pyopm
If necessary, consider using the --user flag if your user account does not have write access to the site-packages folder of your Python 3 installation.
Using PyOPM
Here is a simple example of how to use PyOPM:
frompyopmimportObjectPatternp=ObjectPattern({
'obj': {'eval': [lambdao: isinstance(o, dict)]},
'obj.keys': {'eval': [lambdak: all(isinstance(x, (int, str)) forxink())],
'bind': {'keys': lambdao: o()}},
'obj.values': {'bind': {'values': lambdao: o()}},
'obj.items': {'eval': [lambdai: all(isinstance(y, floatifisinstance(x, int) elseint)
forx, yini())],
'bind': {'items': lambdai: list(i())}},
})
m=p.match({0, 1, 2}) # not a dict -> m is Noneprint(type(m))
m=p.match({0: 0, 'one': 1}) # 0: 0 does not match the rules -> m is Noneprint(type(m))
m=p.match({0: 0.2, 'one': 1}) # match!print(type(m))
withm: # magic: use the objects bound to the names specified aboveprint(keys)
print(values)
print(list(zip(keys, values))) # should be the same as...print(items) # ...this!