Boost logo

Boost :

From: Karl MacMillan (karlmac_at_[hidden])
Date: 2001-06-24 14:13:03


We're developing a interactive system involving a number of separate
boost::python "plugins". Each plugin contains a function "category()"
at the module level that returns a string defining the menu that the
plugin should be added to at run-time.

      string category() { return "MyCategory"; }
...
====
      python::module_builder mPlugin("plugin");
      mPlugin.def(category, "category");
====

This approach works great when compiling for Python 2.0, but with Python
1.5.2, the category function is the same for all plugins that get imported
(it's the category function from the first module that is imported.)

==== (Python session)
>>> import plugina
>>> plugina.category()
'CategoryA'
>>> import pluginb
>>> pluginb.category()
'CategoryA'
==== (New python session)
>>> import pluginb
>>> pluginb.category()
'CategoryB'
>>> import plugina
>>> plugina.category()
'CategoryB'
====

My apologies if this is a known issue. I was unable to find reference to
this on the mailing list. It's one of our design requirements that this
works for Python1.5.2 and 2.x. We would prefer not to resort to naming
functions like plugina_category(), but if that's the only way... It
just doesn't seem to fit with how Python namespaces generally work. Any
suggestions/workarounds? I have tried embedding the function in a small
class, and it doesn't work.

Thanks!

Karl

_____________________________________________________
| Karl W. MacMillan |
| Computer Music Department |
| Peabody Institute of the Johns Hopkins University |
| karlmac_at_[hidden] |
| mambo.peabody.jhu.edu/~karlmac |
-----------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk