Help embedding python
claird at lairds.com
Mon Aug 25 21:33:06 CEST 2003
In article <3F4A57B0.E91D89FC at engcorp.com>,
Peter Hansen <peter at engcorp.com> wrote:
>Zora Honey wrote:
>> Peter Hansen wrote:
>> > Zora Honey wrote:
>> >>My husband and I are writing a program that does a lot of math behind
>> >>the scenes (c++) with a gui front (python/Tkinter). We've decided that
>> >>we want the c++ to be the "driver", and so we want to embed the python.
>> > It's a little unclear (to me) exactly what you're trying to do,
>> > but in any case I can't imagine why you'd want to have C++ "drive"
>> > the Python code (if that's what you meant by "driver", as opposed to
>> > the more common sense as in "device driver") instead of the other
>> > way around.
>> > And my inability to imagine why you want this is compounded by your
>> > choice of Python and Tkinter for the front end. It is much more
>> > common to have the front end be the "driving" code, and the back end
>> > be "driven", especially in CPU-intensive applications as it sounds
>> > like you have here.
>> > -Peter
>> Okay. Let's assume that the choice to embed the python was a
>> well-reasoned decision. Or assume that I want to embed some python for
>> the pure joy of doing so. Can you help?
>No, sorry. I have no particular expertise in embedding Python in a
>C++ application in the way you wish.
>(If I did, and I had an easy answer, I would offer it. If, on the other hand,
>I had no easy answer, and it was going to take some effort on my part,
>I'd be happy to provide that effort if the person I was helping would
>take a moment of his/her time to convince me that it was a well-reasoned
>decision. If, on the other hand, the decision was based on ignorance
>or merely on a frivolous desire to experience the joy of doing so at the
>cost of another's valuable time, I would probably be less inclined to help...)
>(If you assume for a moment that the person who actually *can* help you
>might feel somewhat the same way, you might take a moment to explain
>the background rather than risk looking like you treat others' time as
>less valuable than your own. It may not look that way to you, but I
>was merely trying to help by showing you that at least one person was
>puzzled by your choice. I'm also always interested in learning, so
>I'd still be quite interested in your rationale, if you are willing to
As usual, Peter writes for me. Perhaps it'll be useful to supplement
his remarks, though.
In general, Python's easy to embed; many, MANY people have found suc-
cess with no or little more help than <URL: http://
python.org/doc/current/ext/ext.html > affords.
HOWEVER, I've never embedded Tkinter in that sense. Moreover, I can't
think of a reason I'd want to start now. While I respect the clarity
of your advice to "... assume the choice ...", my own experience has
sooooooo much inclined me to favor extending over embedding (in the
sense of this thread) that I feel no inclination to pursue what I
understand you're describing.
Let me summarize, again: there's abundant material on embedding Python;
I know of none on embedding Tkinter (but wait; does John's book say
anything on the subject? I don't have my copy at hand ...).
Cameron Laird <Cameron at Lairds.com>
More information about the Python-list