Embedding Python and command history

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Bellon

    Embedding Python and command history

    Hi all!

    I'm embedding Python in my own C (or rather Ada, but via the C
    interface) program. Everything runs fine. But I have a small question
    regarding command history. Let's take the simplest example:

    #include <Python.h>

    int main(void)
    {
    Py_Initialize() ;
    PyRun_Interacti veLoop(stdin, "<stdin>");
    Py_Finalize();
    }

    When I compile this an run it, then I get control characters printed
    when I press cursor keys. When I start the "real" python interpreter,
    then I have command history via cursor keys.

    How can I make use of command history when embedded Python via
    PyRun_Interacti veLoop?

    Thanks a lot for your hints in advance!

    --
    Stefan Bellon
  • Stefan Bellon

    #2
    Re: Embedding Python and command history

    Stefan Bellon wrote:
    int main(void)
    {
    Py_Initialize() ;
    PyRun_Interacti veLoop(stdin, "<stdin>");
    Py_Finalize();
    }
    How can I make use of command history when embedded Python via
    PyRun_Interacti veLoop?
    Sorry to follow up my own posting ...

    I found that when I do "import readline" in this simple example, I have
    a working command history. When I do this in my real application, then
    I get the following:
    >>import readline
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    ImportError: /usr/lib/python2.4/lib-dynload/readline.so: undefined
    symbol: PyExc_IOError

    Still experimenting what exactly is causing this.

    This application is not linked against libpython. But it loads a shared
    object at run time which is linked against libpython and which
    contains the call to PyRun_Interacti veLoop. But it looks like this
    "plugin" is not enough to make the symbols known to Python. If I add
    -lpython2.4 to the linker command when building the main application,
    then it works. But this is somewhat against what I was planning to
    achieve when using a plugin: independence of the main application from
    Python.

    Hm.

    --
    Stefan Bellon

    Comment

    Working...