Embedding Python and command history

S

Stefan Bellon

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_InteractiveLoop(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_InteractiveLoop?

Thanks a lot for your hints in advance!
 
S

Stefan Bellon

Stefan said:
int main(void)
{
Py_Initialize();
PyRun_InteractiveLoop(stdin, "<stdin>");
Py_Finalize();
}
How can I make use of command history when embedded Python via
PyRun_InteractiveLoop?

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:
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_InteractiveLoop. 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top