Python embedding question: how to expose a new "builtin"?
Rodrigo B. de Oliveira
rodrigobamboo at hotmail.com
Wed Nov 20 07:23:47 EST 2002
> > <snip language="C++">
> >
> > PyObject* __builtin__ = PyImport_ImportModule("__builtin__");
> > PyObject_SetAttrString(__builtin__, "application",
> > (PyObject*)_pyapplication); Py_DECREF(__builtin__);
> >
> > </snip>
>
> This looks to me like the correct way to do what you ask.
>
Thanks.
>
> > Notes:
> > * _pyapplication is an instance of a C new style class
>
> What IS "a C new style class"...?
Sorry. I meant a class defined in C instead of a class defined in
python. Too much going on here ;-)
>
> > The problem is: the modules can see the name "application" but
> > dir(application) returns [] and if I try to access any of application's
> > attributes I get an AttributeError.
> >
> > Thoughts?
>
> Looks to me like the problem is with the _pyapplication object
> rather than with the exposing of it in the built-ins module. What happens
> if you architect another way to let Python code get at that same object?
> Does "is" show the two ways give the same object, and what are the
> symptoms on e.g. dir for each? I think you should get the same
> results, confirming the problem is with the object and not with
> the way you're choosing to expose it.
You are right. I tried that and the results were the same.
I don't have the source code here at the office I'll take a deeper
look at the _pyapplication type definition again tonite and probably
will be bothering you again soon ;-)
Thank you very much.
Rodrigo
More information about the Python-list
mailing list