[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..&nbsp; I have read \
everything I can on this subject..<br>And I&#39;ve tried many many possible \
solutions..&nbsp;&nbsp; And lost many hours actually (blech).&nbsp; <br><br>Some of \
the e-mails in these newsgroups from long ago are quite misleading..&nbsp; Other \
e-mails on this topic seem to be inaccessible.&nbsp; Much of &quot;piper-mail&quot; \
is gone it seems, or relocated beyond the reach of google. (didn&#39;t know that was \
still possible!)<br> <br>The only solution that works so far:<br><br>given that \
I&#39;ve created dD_script and dD_object and dD* modules \
previously..<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object dD = \
object(handle&lt;&gt;(PyImport_AddModule (&quot;dD&quot;)));<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; char *statement = <br> <br>// import what I need, I guess I \
don&#39;t need types actually<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &quot;import sys, types\n&quot;\<br><br>// this is importing all \
of the modules that I&#39;ve already created..<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;import dD, dD_script, dD_object, \
dD_types, dD_ui, dD_device, dD_render, dD_internal\n&quot;\<br> <br>// this is \
assigning them to the parent &quot;package&quot;<br> &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;dD.Script = \
sys.modules[&#39;dD.Script&#39;] = dD_script\n&quot;\<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;dD.Object = \
sys.modules[&#39;dD.Object&#39;] = dD_object\n&quot;\<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;dD.Types = \
sys.modules[&#39;dD.Types&#39;] = dD_types\n&quot;\<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;dD.UI = \
sys.modules[&#39;dD.UI&#39;] = dD_ui\n&quot;\<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;dD.Device = \
sys.modules[&#39;dD.Device&#39;] = dD_device\n&quot;\<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;dD.Render = \
sys.modules[&#39;dD.Render&#39;] = dD_render\n&quot;\<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &quot;dD.Internal = \
sys.modules[&#39;dD.Internal&#39;] = dD_internal&quot;\<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ;<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
exec(statement, mainDict, mainDict);<br><br><br>The non-solutions that don&#39;t \
work:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; object dD = \
object(handle&lt;&gt;(PyImport_AddModule (&quot;dD&quot;)));<br> \
<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dD.attr(&quot;Script&quot;) = \
handle&lt;&gt;(PyImport_ImportModule(&quot;dD_script&quot;));<br> &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dD.attr(&quot;Object&quot;) = \
handle&lt;&gt;(PyImport_ImportModule(&quot;dD_object&quot;));<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dD.attr(&quot;Types&quot;) = \
handle&lt;&gt;(PyImport_ImportModule(&quot;dD_types&quot;));<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dD.attr(&quot;UI&quot;) = \
handle&lt;&gt;(PyImport_ImportModule(&quot;dD_ui&quot;));<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dD.attr(&quot;Device&quot;) = \
handle&lt;&gt;(PyImport_ImportModule(&quot;dD_device&quot;));<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dD.attr(&quot;Render&quot;) = \
handle&lt;&gt;(PyImport_ImportModule(&quot;dD_render&quot;));<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; dD.attr(&quot;Internal&quot;) = \
handle&lt;&gt;(PyImport_ImportModule(&quot;dD_internal&quot;));<br>

<br>&nbsp; I also tried manipulating the dictionary of the dD module instead of \
attributes above<br><br><br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; object sys = \
import(&quot;sys&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dict sysDict \
(sys.attr(&quot;__dict__&quot;));<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
sysDict[&quot;dD.Script&quot;] = dD[&quot;Script&quot;];<br> &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; sysDict[&quot;dD.Object&quot;] = dD[&quot;Object&quot;];<br> \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sysDict[&quot;dD.Types&quot;] = \
dD[&quot;Types&quot;];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
sysDict[&quot;dD.UI&quot;] = dD[&quot;UI&quot;];<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; sysDict[&quot;dD.Device&quot;] = \
dD[&quot;Device&quot;];<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
sysDict[&quot;dD.Render&quot;] = dD[&quot;Render&quot;];<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sysDict[&quot;dD.Internal&quot;] = \
dD[&quot;Internal&quot;];<br><br>well if dD is the object these direct [] indexes \
fail, if it is a dict, the solution still doesn&#39;t \
work<br><br><br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dict sysModules \
(sys.attr(&quot;modules&quot;));<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
sysModules[&quot;dD.Script&quot;] = \
dD.attr(&quot;Script&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
sysModules[&quot;dD.Object&quot;] = dD.attr(&quot;Object&quot;);<br> \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sysModules[&quot;dD.Types&quot;] = \
dD.attr(&quot;Types&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
sysModules[&quot;dD.UI&quot;] = dD.attr(&quot;UI&quot;);<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; sysModules[&quot;dD.Device&quot;] = \
dD.attr(&quot;Device&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
sysModules[&quot;dD.Render&quot;] = dD.attr(&quot;Render&quot;);<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sysModules[&quot;dD.Internal&quot;] = \
dD.attr(&quot;Internal&quot;);<br><br>if I do dict stuff instead of attribute, still \
doesn&#39;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