[C++-sig] boost.pyton scope bug?

Jim Bosch talljimbo at gmail.com
Fri Mar 19 21:37:00 CET 2010

On Fri, 2010-03-19 at 19:55 +0000, Gennadiy Rozental wrote:
> I am doing something like this in export part of mymodule:
> scope S = class_<X>("X", no_init );
> class_<Y>( "Y",... )
> ...
> ;
> In Python I do see mymodule.X.Y, but mymodule.X.Y.__name__ is 'mymodule.Y'

Hmm.  In the same situation, I simply get mymodule.X.Y.__name__ ==
'Y' (and mymodule.X.__name__ == 'X') - no module prefixes at all.  That
matches the pure-python inner class result, at least on my system.

I do get mymodule.X.__module__ == 'mymodule' and mymodule.X.Y.__module__
== 'mymodule', but that's also correct as far as mirroring the
pure-python inner class result.

(This is Python 2.6.4; it may have changed in 3.0, but I certainly hope
it doesn't depend on anything else).

Note that you can change the __module__ attribute; I often import my
wrapped names into different submodules in a package and adjust their
__module__ accordingly to make a Python interface that mirrors the C++
namespaces better - but all that has to be done in Python; boost python
can't do it for you (maybe Py++ could?)

Jim Bosch

More information about the Cplusplus-sig mailing list