[C++-sig] Need help on enum--a concrete example
Peter Bienstman
Peter.Bienstman at rug.ac.be
Tue Sep 10 16:33:20 CEST 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sunday 08 September 2002 23:41, David Abrahams wrote:
> Nevermind all that; I implemented real enum support ;-).
>
> Now given Min's example enum:
>
> enum choice { red, blue };
>
> the construct:
>
> enum_<choice>("choice")
> .value("red", red)
> .value("blue", blue)
> ;
>
> can be used to expose it to Python. The new enum type is created in the
> current scope(), which is usually the current module.
>
> You can access those values in Python as
>
> >>> extension_module.choice.red
>
> extension_module.choice.red
Small question: is there a trick to pollute the global namespace with the
constants, such that one can write just 'red' in Python, rather than
'choice.red'?
I know it's less clean, but it's easier for the user and ties in better with
Python's weak typing.
Cheers,
Peter
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9fgKz4dgPAIjyquoRAh0CAJ45JBhd5ztlZXL8NIyHPbN/zkdKuwCfT+fJ
p8as3LXKccOgzO0LpVObl2k=
=h7Kt
-----END PGP SIGNATURE-----
More information about the Cplusplus-sig
mailing list