tho*_*att 45
这是一个非常简单的例子.它有三个文件:
你可以在插件目录中添加更多的插件,这个脚本会循环遍历它们.
http://lateral.netmanagers.com.ar/weblog/posts/BB923.html(已存档)还有另一个更复杂的例子.
yapsy-example.py
from yapsy.PluginManager import PluginManager
def main():
# Load the plugins from the plugin directory.
manager = PluginManager()
manager.setPluginPlaces(["plugins"])
manager.collectPlugins()
# Loop round the plugins and print their names.
for plugin in manager.getAllPlugins():
plugin.plugin_object.print_name()
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
插件\ plugin1.py
from yapsy.IPlugin import IPlugin
class PluginOne(IPlugin):
def print_name(self):
print "This is plugin 1"
Run Code Online (Sandbox Code Playgroud)
插件\ plugin1.yapsy-插件
[Core]
Name = Plugin 1
Module = plugin1
[Documentation]
Author = John Smith
Version = 0.1
Website = http://lotsofplugins.com
Description = My first plugin
Run Code Online (Sandbox Code Playgroud)