Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting python attribute into the C space #6

Open
belangeo opened this issue Oct 29, 2019 · 0 comments
Open

Getting python attribute into the C space #6

belangeo opened this issue Oct 29, 2019 · 0 comments

Comments

@belangeo
Copy link
Owner

From Chris Csikszentmihalyi mail:

Here's an example of getting an object's value from python into the C space:

138 INLINE int pyo_get_python_int(PyThreadState *interp) {                         
139     PyObject *module, *obj;                                                    
140     PyEval_AcquireThread(interp);                                              
141     module = PyImport_AddModule("main");                                                                                 
142     obj = PyObject_GetAttrString(module, "freq");                              
143     PyEval_ReleaseThread(interp);                                              
144                                                                                
145     long foobar = PyInt_AsLong(obj);                                           
146     return (int) foobar;                                                       
147 }                                    
This seems to work well and causes no mode switches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant