views:

54

answers:

1

I'm implementing a simple plugin framework for a little Python program and wonder whether there are general best practices for transferring data to plugins?

I'm new to Python and this is what I have come up with so far after doing some reading: I will not use global variables, instead data is going to be passed to the plugin classes on instantiation. At this stage, I see two alternatives.

  1. pass task-specific data to plugins, don't give plugins access to any other data
  2. pass all the data to which any plugin should have access

What are the pros and cons of these two alternatives? Are there any other ways or best practices that I am unaware of?

\edit: Any other answers? Do you need more information on what I intend to do? Suggesting generic solutions would be OK as well.

+1  A: 

I like the way wxPython does events. Pass an event object to the plugin with what you think is the relevant data, but also provide an API for every plugin to access the full state of the application.

For example, in wxMouseEvent has x and y properties. But also (like every other event object) has get GetEventObject (and every object has GetParent ....)

lazy1
That's interesting, I will look up details.
lecodesportif