On 07/12/2007, Campbell Barton cbarton@metavr.com wrote:
would this work?
PyObject *mod_sys;
mod_sys = PyImport_ImportModule( "sys" ); /* new ref */ dict = PyModule_GetDict( mod_sys ); /* borrowed ref */
Don't do this, it breaks the module as object transparency. In some solutions, python modules can be replaced by proxy objects that deman load the real object, and they hook into getattr, so this solution won't work for them.
Modules are normal python objects. You can use PyObject_GetAttrString as usual...
PyObject *key, *value;
int pos = 0;
if (dict) { while (PyDict_Next(dict, &pos, &key, &value)) { /* do stuff here */ } }
is there a tp_getattr equivalent for module? i want to dynamically check if an object exists in a module space dynamically and return it if it does.
currently i have mymodule.getattr("foo") where getattr is my lookup function plugged
On Wed, 2007-12-05 at 17:56 -0600, Anton Tropashko wrote: thru PyMethodDef/Py_ModuleInit
i want to be able to access foo directly, like so: mymodule.foo
capi-sig mailing list capi-sig@python.org http://mail.python.org/mailman/listinfo/capi-sig
capi-sig mailing list capi-sig@python.org http://mail.python.org/mailman/listinfo/capi-sig
-- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert