[capi-sig] Constants in classes?

Gustavo Carneiro gjcarneiro at gmail.com
Thu Dec 27 15:02:34 CET 2007


On 27/12/2007, Remi K. <remi.k2620 at gmail.com> wrote:
>
> Thanks for the answer. I did what you told me after the module's
> initialisation, it compiles well, however when I try to load my module
> with
> python it throws the error:
> TypeError: can't set attributes of built-in/extension type 'sfColor'
> Any idea?


OK, maybe that only works for types that can be subclassed.

Alternatively:

PyObject *enum_value = PyInt_FromLong(123);
PyDict_SetItemString(FooBar_Type.tp_dict, "name",  enum_value)
Py_DECREF(enum_value);

On Dec 27, 2007 12:53 PM, Gustavo Carneiro <gjcarneiro at gmail.com> wrote:
>
> > On 27/12/2007, Remi K. <remi.k2620 at gmail.com> wrote:
> >
> > > Hello,
> > > I am currently writing a python wrapper for the C++ SFML library (
> > > http://sfml.sourceforge.net).
> > > I know there is PyModule_AddIntConstant for adding constants to a
> > > module,
> > > but how can I add a constant to one of my module's classes? Is there
> an
> > > easy
> > > way to wrap enumerations?
> > > Any help is appreciated :)
> >
> >
> > Any type is an object:
> >
> > PyObject *enum_value = PyInt_FromLong(123);
> > PyObject_SetAttrString((PyObject *) &FooBar_Type, enum_value);
> > Py_DECREF(enum_value);
> >
> > --
> > Gustavo J. A. M. Carneiro
> > INESC Porto, Telecommunications and Multimedia Unit
> > "The universe is always one step beyond logic." -- Frank Herbert
> _______________________________________________
> capi-sig mailing list
> capi-sig at python.org
> http://mail.python.org/mailman/listinfo/capi-sig
>



-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert


More information about the capi-sig mailing list