[prev in list] [next in list] [prev in thread] [next in thread]
List: python-cpp-sig
Subject: [C++-sig] built-in submodule creation
From: "Tim Prepscius" <timprepscius () gmail ! com>
Date: 2009-01-15 19:24:58
Message-ID: 6fcb94430901151124l40861795t691d7320f8e477ff () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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
[Attachment #5 (text/html)]
Greetings,<br><br>I am trying to create built-in sub modules.. I have read \
everything I can on this subject..<br>And I've tried many many possible \
solutions.. And lost many hours actually (blech). <br><br>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!)<br> <br>The only solution that works so far:<br><br>given that \
I've created dD_script and dD_object and dD* modules \
previously..<br><br> object dD = \
object(handle<>(PyImport_AddModule ("dD")));<br> \
char *statement = <br> <br>// import what I need, I guess I \
don't need types actually<br> \
"import sys, types\n"\<br><br>// this is importing all \
of the modules that I've already created..<br> \
"import dD, dD_script, dD_object, \
dD_types, dD_ui, dD_device, dD_render, dD_internal\n"\<br> <br>// this is \
assigning them to the parent "package"<br> \
"dD.Script = \
sys.modules['dD.Script'] = dD_script\n"\<br> \
"dD.Object = \
sys.modules['dD.Object'] = dD_object\n"\<br> \
"dD.Types = \
sys.modules['dD.Types'] = dD_types\n"\<br>
"dD.UI = \
sys.modules['dD.UI'] = dD_ui\n"\<br> \
"dD.Device = \
sys.modules['dD.Device'] = dD_device\n"\<br> \
"dD.Render = \
sys.modules['dD.Render'] = dD_render\n"\<br>
"dD.Internal = \
sys.modules['dD.Internal'] = dD_internal"\<br> \
;<br><br> \
exec(statement, mainDict, mainDict);<br><br><br>The non-solutions that don't \
work:<br> object dD = \
object(handle<>(PyImport_AddModule ("dD")));<br> \
<br><br> dD.attr("Script") = \
handle<>(PyImport_ImportModule("dD_script"));<br> \
dD.attr("Object") = \
handle<>(PyImport_ImportModule("dD_object"));<br> \
dD.attr("Types") = \
handle<>(PyImport_ImportModule("dD_types"));<br> \
dD.attr("UI") = \
handle<>(PyImport_ImportModule("dD_ui"));<br>
dD.attr("Device") = \
handle<>(PyImport_ImportModule("dD_device"));<br> \
dD.attr("Render") = \
handle<>(PyImport_ImportModule("dD_render"));<br> \
dD.attr("Internal") = \
handle<>(PyImport_ImportModule("dD_internal"));<br>
<br> I also tried manipulating the dictionary of the dD module instead of \
attributes above<br><br><br><br> object sys = \
import("sys");<br> dict sysDict \
(sys.attr("__dict__"));<br> \
sysDict["dD.Script"] = dD["Script"];<br> \
sysDict["dD.Object"] = dD["Object"];<br> \
sysDict["dD.Types"] = \
dD["Types"];<br> \
sysDict["dD.UI"] = dD["UI"];<br> \
sysDict["dD.Device"] = \
dD["Device"];<br> \
sysDict["dD.Render"] = dD["Render"];<br>
sysDict["dD.Internal"] = \
dD["Internal"];<br><br>well if dD is the object these direct [] indexes \
fail, if it is a dict, the solution still doesn't \
work<br><br><br><br> dict sysModules \
(sys.attr("modules"));<br> \
sysModules["dD.Script"] = \
dD.attr("Script");<br> \
sysModules["dD.Object"] = dD.attr("Object");<br> \
sysModules["dD.Types"] = \
dD.attr("Types");<br> \
sysModules["dD.UI"] = dD.attr("UI");<br> \
sysModules["dD.Device"] = \
dD.attr("Device");<br> \
sysModules["dD.Render"] = dD.attr("Render");<br>
sysModules["dD.Internal"] = \
dD.attr("Internal");<br><br>if I do dict stuff instead of attribute, still \
doesn't work..<br><br>===================<br><br>Is there a better way for me to \
do this, than executing the python code segment?<br> Does anyone know what is going \
on behind the scenes in the python code execution?<br><br>Thanks,<br><br>-tim<br>
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic