views:

77

answers:

3

Hello.

This seems to be sort of what I want, except I want to make an instance of a C PyObject in another C module.

http://stackoverflow.com/questions/1147452/create-instance-of-a-python-class-declared-in-python-with-c-api

But I am not able to find the documentation for using a Python module from C. I can't seem to find the relevent docs online as everyone just talks about extending Python with C.

My issue is that I have a Pygame which I want to speed up. So I am making a C module which needs access to Pygame. How do I import pygame? I don't want to import two copies, right? The coding part I can figure out, I just don't know how to configure and link the code. I know I must be missing some docs, so if anyone can point me in the right direction, I'd be much obliged.

+1  A: 

The trick is to write the normal Python routine, but in C. Use PyImport_ImportModule(), PyObject_GetAttr(), and PyObject_Call() as appropriate.

Ignacio Vazquez-Abrams
A: 

I googled it in a single "I'm feeling lucky."

Jive Dadson
A: 

I'm sorry I can't edit my post, this is the OP.

Sorry I reread my post and realized my wording was terrible.

If you have pygame installed you can look in your Python/include directory and find pygame header files. What are they for? I thought that your C module could access the pygame C module directly, so that your python script AND your C module used the same pygame instance.

Clarification anyone?

Dogman