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

Gennadiy Rozental rogeeff at gmail.com
Fri Mar 19 22:44:55 CET 2010

Jim Bosch <talljimbo <at> gmail.com> writes:

> 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.

You right. I got it wrong when reported the error. The problem, is that when I
print mymodule.X.Y I am getting <class 'mymodule.Y'> which is wrong IMO
> 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.

Well I hoped to mimic some kind of subnamespace with scope. Thus the module
should be mymodule.X or the name should be X.Y

> 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?)

Can you show an example?

I am currently tweaking this Python as well (post loading) like this:

mymodule.X.Y.__name__ = 'X.Y'

It's still not completely satisfactory, since help(mymodule.X) does not do the
right job, but at least it does not show Y as 'mymodule.Y'


More information about the Cplusplus-sig mailing list