Re: [C++-sig] Re: Boost.Python unnamed enums at global scope
by Nicodemus other posts by this author
Aug 2 2003 8:55PM messages near this date
Re: [C++-sig] Re: Boost.Python unnamed enums at global scope
|
[C++-sig] numarray and boost.python
----- Original Message -----
From: "David Abrahams" <dave@[...].com>
To: "Niall Douglas" <ned@[...].com> ; "pysig" <c++-sig@[...].org>
Sent: Saturday, August 02, 2003 5:21 PM
Subject: [C++-sig] Re: Boost.Python unnamed enums at global scope
>
> Hi Niall,
>
> Please post Boost.Python questions to the C++-sig (see
> http://www.boost.org/more/mailing_lists.htm).
>
> "Niall Douglas" <ned@[...].com> writes:
> > I was wondering if Boost.Python could be extended such that:
> >
> > enum_<int>("").value("CONST", CONST);
> >
> > .. would place its members in the highest scope possible ie; you'd
> > access it as my_module.CONST.
>
> We have an export_values() member function which accomplishes that.
>
> http://www.boost.org/libs/python/doc/v2/enum.html#enum_-spec
>
> > I suggest this because the library I'm creating bindings for has
> > loads of unnamed enums at global scope for creating constants and
> > sticking them in some "unnamed" scope is counter-intuitive. Since
> > pyste has to deal with these, it creates problems :(
Nice, I didn't know that either. I think this mirrors the enum behaviour of
C++ better. How should Pyste support this? I believe it is more interesting
if Pyste always called export_values(), but this would break backwards
compability. Thoughts?
Niall, another solution would be to explicitly export the names to the
global namespace in the Python side (untested):
# my_module.py
import _my_module # this is the extension module
for name, value in _my_module.unnamed.__dict__:
globals()[name] = value
with this, your users now just have to:
import my_module
x = my_module.CONST
etc etc
_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
|