[C++-sig] built-in submodule creation
Tim Prepscius
timprepscius at gmail.com
Thu Jan 15 20:24:58 CET 2009
Greetings,
I am trying to create built-in sub modules.. I have read everything I can
on this subject..
And I've tried many many possible solutions.. And lost many hours actually
(blech).
Some of the e-mails in these newsgroups from long ago are quite
misleading.. Other e-mails on this topic seem to be inaccessible. Much of
"piper-mail" is gone it seems, or relocated beyond the reach of google.
(didn't know that was still possible!)
The only solution that works so far:
given that I've created dD_script and dD_object and dD* modules previously..
object dD = object(handle<>(PyImport_AddModule ("dD")));
char *statement =
// import what I need, I guess I don't need types actually
"import sys, types\n"\
// this is importing all of the modules that I've already created..
"import dD, dD_script, dD_object, dD_types, dD_ui, dD_device,
dD_render, dD_internal\n"\
// this is assigning them to the parent "package"
"dD.Script = sys.modules['dD.Script'] = dD_script\n"\
"dD.Object = sys.modules['dD.Object'] = dD_object\n"\
"dD.Types = sys.modules['dD.Types'] = dD_types\n"\
"dD.UI = sys.modules['dD.UI'] = dD_ui\n"\
"dD.Device = sys.modules['dD.Device'] = dD_device\n"\
"dD.Render = sys.modules['dD.Render'] = dD_render\n"\
"dD.Internal = sys.modules['dD.Internal'] = dD_internal"\
;
exec(statement, mainDict, mainDict);
The non-solutions that don't work:
object dD = object(handle<>(PyImport_AddModule ("dD")));
dD.attr("Script") = handle<>(PyImport_ImportModule("dD_script"));
dD.attr("Object") = handle<>(PyImport_ImportModule("dD_object"));
dD.attr("Types") = handle<>(PyImport_ImportModule("dD_types"));
dD.attr("UI") = handle<>(PyImport_ImportModule("dD_ui"));
dD.attr("Device") = handle<>(PyImport_ImportModule("dD_device"));
dD.attr("Render") = handle<>(PyImport_ImportModule("dD_render"));
dD.attr("Internal") =
handle<>(PyImport_ImportModule("dD_internal"));
I also tried manipulating the dictionary of the dD module instead of
attributes above
object sys = import("sys");
dict sysDict (sys.attr("__dict__"));
sysDict["dD.Script"] = dD["Script"];
sysDict["dD.Object"] = dD["Object"];
sysDict["dD.Types"] = dD["Types"];
sysDict["dD.UI"] = dD["UI"];
sysDict["dD.Device"] = dD["Device"];
sysDict["dD.Render"] = dD["Render"];
sysDict["dD.Internal"] = dD["Internal"];
well if dD is the object these direct [] indexes fail, if it is a dict, the
solution still doesn't work
dict sysModules (sys.attr("modules"));
sysModules["dD.Script"] = dD.attr("Script");
sysModules["dD.Object"] = dD.attr("Object");
sysModules["dD.Types"] = dD.attr("Types");
sysModules["dD.UI"] = dD.attr("UI");
sysModules["dD.Device"] = dD.attr("Device");
sysModules["dD.Render"] = dD.attr("Render");
sysModules["dD.Internal"] = dD.attr("Internal");
if I do dict stuff instead of attribute, still doesn't work..
===================
Is there a better way for me to do this, than executing the python code
segment?
Does anyone know what is going on behind the scenes in the python code
execution?
Thanks,
-tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090115/d2301090/attachment.htm>
More information about the Cplusplus-sig
mailing list