embedding Python in C

Gordon McMillan gmcm at hypernet.com
Wed Dec 22 19:26:39 EST 1999


Curtis Jensen asks:

> From a C file, how can I get values from a Python Class?  
> For Example:
> 
> File: Test.py
> class Klass:
>   def __init__(self):
>     self.a = 1
>     self.b = 2
>     self.c = 3
> 
> How can I get the values of a,b, and c from within a C function?
> Thanks

Assuming you mean "from an instance of Klass", the answer 
is the same way you would in Python. Well, in dynamic 
Python. The equivalent of getattr(obj, name) is 
PyObject_GetAttrString(o, name).

- Gordon




More information about the Python-list mailing list