trouble embedding python

Jp Calderone exarkun at intarweb.us
Fri Jun 6 08:13:27 CEST 2003


On Fri, Jun 06, 2003 at 01:15:32AM +0000, TheDustbustr wrote:
> [snip]
> 
> 
> *** BEGIN main() ***
> ...
> Script_LoadScript(script, "pobj");
> result=PyDict_GetItemString(script.pDict, "Human.str");

  This isn't right.  You need to get "Human" separately from "str".

    PyObject* human = PyObject_GetAttrString(script.pDict, "Human");
    if (human == NULL) {
        ...
    }
    PyObject* str = PyObject_GetAttrString(human, "str");
    if (str == NULL) {
        ...
    }
    ...


> [snip]

  Stepping back a bit: consider not embedding at all, though.  It is more
effort for less result than writing extension modules.

  http://www.twistedmatrix.com/users/glyph/rant/extendit.html is a
reasonable summary of the differences between the two strategies, and why
you might select one over the other.

  Stepping back even more: consider why you would use any language other
than Python at all.  Python should be sufficient for anything except
interoperating with native libraries, which do require some wrapping.  If
you're using C++ for performance, consider optimizing -after- you've written
a fair part of your project, rather than before.  Premature optimization
leads to inflexible software, and closes down avenues for later optimization
when the problems may be better understood.

  Hope this helps,

  Jp





More information about the Python-list mailing list