Imperium是一个python包,允许您轻松计算python表达式

imperium的Python项目详细描述


帝国

Imperium is a python package that allows you to easily evaluate python expressions

安装

pip install imperium

使用

^{pr2}$

要访问给定主题中的数据,请使用上面所示的“$subject”键。在

检查主题是否具有属性

fromimperium.evaluatorimportExpressionobj={'name':'iPhone','model':'11 Pro','price':1299.90,'state':'new'}someother_obj={'name':'John Doe'}expr=Expression()res=expr.evaluate('exists("$subject.price", $subject)',subject=obj,source=someother_obj)# REMINDER: "$subject" key let's you access the object that you passed to the evaluate method (obj in this case)print(res)# Output: True

测试正则表达式

fromimperium.evaluatorimportExpressionobj={'name':'iPhone','model':'11 Pro','price':1299.90,'state':'new'}buyer={'fullname':'John Doe'}# Passing the name attribute of the subject# REMINDER: "$subject" let's you access the object/subject passed to the evaluate method (obj in this case)# and "$source" let's you access the optional source object passed to the evaluate method expression="exists('$subject.name', $subject) && matches('IPHONE', $subject['name'], 'i')"expr=Expression()res=expr.evaluate(expression,subject=obj,source=buyer)print(res)# Output: True

Imperium有内置函数来简化某些操作/验证。在

FunctionArgument(s)Description
exists()key (Ex: $subject.price), $subjectChecks if the given attribute/key exists in the given subject.
matches()regex, value, flag (i or m)Tests a regular expression
date()datestring, formatdatestring and format are both optional, provide them to the function if you want to convert a date string to date object.
If these two arguments are left emtpy, the function returns date object with current date and time.
date_modify()date, operation (+ | -), valuetype (days | months | years), value: intThis function can add and subtract days, months and years from a date object.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在Jsp中下载文件另存为Pdf   java发布onLongClickListener Android   java转换输出以在适用时包括折扣   java从手动启动了Spring启动应用程序。罐子不能正常工作   字符串Java控制台程序,用于打印用户输入的摘要   java如何在jsp中的指定位置显示jfreechart   amazon web服务AWS Cognito SignIn与用于桌面应用程序的Java SDK   java tomcat应用程序已启动,但立即销毁   java如何查找ImportTsv的hdfsinputdir   java如何在edittext上创建特定的输入类型?可访问的输入是罗马数字M D C X V I   使用hsb模型Java设置bg颜色的swing动画   java在几个JLabel中设置相同的gif作为图标   java使用jersey仅在rest服务中使用csv   Java:有可能知道web服务器使用的JVM实例吗   反射Java注册用@MyAnnotation注释的所有类