standalone vs embedded interpreter

N

Nick Gnedin

Folks,

When simply I embed the interpreter:

#include "Python.h"

int main()
{
Py_Initialize();
PyRun_InteractiveLoop(stdin,"test");
Py_Finalize();

return 0;
}

I expect it to behave the same way as if I was running it as a
standalone program. On Windows this is indeed the case, but on my Linux
box (Python 3.3.1 (default, Apr 8 2013, 22:33:31) [GCC 4.1.2 20080704
(Red Hat 4.1.2-51)]) I get a different behavior in handling console
input. A standalone interpreter cycles though the input history when I
use up and down arrows - say, I type this code:

put at the prompt - does anyone know what I am doing wrong?

Many thanks for any hint,

Nick
 
R

rusi

Folks,

When simply I embed the interpreter:

        #include "Python.h"

        int main()
        {
          Py_Initialize();
          PyRun_InteractiveLoop(stdin,"test");
          Py_Finalize();

          return 0;
        }

I expect it to behave the same way as if I was running it as a
standalone program. On Windows this is indeed the case, but on my Linux
box (Python 3.3.1 (default, Apr  8 2013, 22:33:31) [GCC 4.1.2 20080704
(Red Hat 4.1.2-51)]) I get a different behavior in handling console
input. A standalone interpreter cycles though the input history when I
use up and down arrows - say, I type this code:

 >>> 1
1
 >>> a=4
 >>> a
4

If I now press an <up> key in a standalone interpreter, I get 'a' placed
at the prompt (my previous command). However, in an embedded code I get

 >>> ^[[A

put at the prompt - does anyone know what I am doing wrong?

Many thanks for any hint,

Nick

You probably need readline
See http://docs.python.org/2/library/cmd.html#cmd.Cmd.cmdloop
[Also try Control-P COntrol-N for up and down arrow]
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top