ITPub博客

首页 > 应用开发 > Python > Python中的Director插件,你需要了解一下

Python中的Director插件,你需要了解一下

原创 Python 作者:python交流 时间:2019-03-12 21:20:49 0 删除 编辑

前言

Director 是一个Python的类库用来开发命令行工具的插件,利用它可以很方便的添加新的功能。

下面是一个简单的例子:

#!/usr/bin/env pythonimport exceptionsimport sysfrom director import ActionRunnerfrom director.filter import ExceptionFilterfrom director.filter import Filterif __name__ == '__main__':    # Create and use exception filters
    # Note you don't have to use filters. If you don't pass filter in
    # to ActionRunner.run filters won't be used.
    filter = Filter()
    filter.register_filter(ExceptionFilter(exceptions.IOError, "TEST %s"))
    filter.register_filter(ExceptionFilter(exceptions.TypeError, "NO! %s"))    # 'actions.package' is the package that holds the allowed plugin actions
    ar = ActionRunner(sys.argv, 'actions.package')
    ar.run(filter)·


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69912078/viewspace-2638223/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
上路:9458 中路:79 下来025 有干货

注册时间:2019-03-04

  • 博文量
    188
  • 访问量
    297955