Safe execute expr code.
Project description
📦 perfect-eval
Safe eval module
Installation
pip install -i https://mirrors.aliyun.com/pypi/simple/ --extra-index-url https://pypi.org/simple/ perfect-eval
Example
from perfect_eval import eval_expr
eval_expr("print('hello world')", {"print": print})
# output: hello world
print(eval_expr("now.strftime('%m-%d')", {"now": datetime.now()}))
# output: 10-31
print(eval_expr("a + b", {"a": 123, "b": 456}))
# output: 579
print(eval_expr("f'{a} + {b} = {a + b}'", {"a": 123, "b": 456}))
# output: 123 + 456 = 579
print(eval_expr("match(a, [(1, '11'), (2, '22'), (3, '33')], default='ooo')", {"a": 1}))
# output: 11
print(eval_expr(r"re.sub(r'\d+', '很多', count)", {"count": '10个'}))
# output: 很多个
To Do
- Be the best version of you.
More Resources
- [perfect-eval] on github.com
- Official Python Packaging User Guide
- The Hitchhiker's Guide to Packaging
- Cookiecutter template for a Python package
License
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
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
perfect-eval-0.0.10.tar.gz
(16.3 kB
view hashes)
Built Distribution
Close
Hashes for perfect_eval-0.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e921baf1435c2a749a4035bb8ef240024443a277b6cf793f12579253a3341129 |
|
MD5 | 5a57841522a02586d348eaaa5810eb0c |
|
BLAKE2b-256 | 3202838a53691352d789904f9099262999e4c588dee3572c1dc43bf9c4c0e31b |