[C++-sig] Re: Boost.Python unnamed enums at global scope

Nicodemus nicodemus at globalite.com.br
Sat Aug 2 22:55:25 CEST 2003


----- Original Message -----
From: "David Abrahams" <dave at boost-consulting.com>
To: "Niall Douglas" <ned at nedprod.com>; "pysig" <c++-sig at python.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 at nedprod.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





More information about the Cplusplus-sig mailing list