FAQ
Hey

1. I've embedded python in a simple application. I've created a custom
object and I've added it to the global dictionary with the name "capi". I
then load a python module with PyImport_ImportModuleEx passing my global
dictionary in as the globals parameter. The module loads correctly.

I then try instance an object from the module and I get this error:

global name 'capi' is not defined.

How do I get the module to check the global namespace for capi? It loaded it
ok with my passing globals as an optional parameter?

The reason I need an instance of the object is that I need the SELF pointer
passed through from python.

2. Is it possible to inherit from a module. I want to directly inherit from
one of my C custom objects. The only way I can see to do this currently is
to create a python proxy object that contains a C object and the overload
the get/set attr methods so that it correctly sends the requests to the C
object? Is there a better way around this? It seems a bit of a waste...

Thanks again
Lloyd

Search Discussions

  • Raymond Hettinger at Jan 6, 2003 at 2:33 pm
    "Lloyd"
    2. Is it possible to inherit from a module. I want to directly inherit from
    one of my C custom objects. The only way I can see to do this currently is
    to create a python proxy object that contains a C object and the overload
    the get/set attr methods so that it correctly sends the requests to the C
    object? Is there a better way around this? It seems a bit of a waste...
    Yes. For a worked out example, look in the current CVS for
    Python/dist/src/Modules/_randommodule.c

    Be sure to include Py_TPFLAGS_BASETYPE in the tp_flags slot
    and to create your object with self = (YourObject *)type->tp_alloc(type, 0);
    instead of the usual PyObject_New.


    Raymond Hettinger

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJan 6, '03 at 9:21a
activeJan 6, '03 at 2:33p
posts2
users2
websitepython.org

2 users in discussion

Lloyd: 1 post Raymond Hettinger: 1 post

People

Translate

site design / logo © 2022 Grokbase