任何类的属性路由器/链接器
AttributeRouter的Python项目详细描述
属性路由器
属性路由器是一个库,它链接类的属性调用,如果regex匹配,则返回方法。
快速启动
importrefromattribute_routerimportRouterclassPrinter(Router):def__init__(self):super().__init__(routes={re.compile(" (.*) PRINT"):self.print_match},join_char=" ")defprint_match(self,prefix,_match):print(prefix,_match.group(1))Printer().hello.world('!').again.PRINT("Hello and")
因此,为了定义路由,我们使用编译的regex和方法本身也不要忘记从attribute_router.Router
安装
库在pypi上,所以只需运行
pip install AttributeRouter