embedded python question

Keith S. keith_s at ntlworld.nospam.com
Wed Jul 24 15:12:24 EDT 2002


Just wrote:

> Have a look at code.py in the std library.

Hmm, that looks interesting...

So in my C code I've something like:

char *code = "class Sout:\n"
              "    def write(self, s):\n"
              "        output(s)\n"
              "\n"
              "class Sin:\n"
              "    def __init__(self, prompt):\n"
              "        input(prompt)\n"
              "\n"
              "import sys\n"
              "from code import *\n"
              "from gld import *\n"
              "sys.stdout = Sout()\n"
              "sys.stdin = None\n"
              "interact('---Starting Python---, Sin)\n"
PyRun_SimpleString(code);

The input() C function returns Py_BuildValue("s", cmd ), where cmd
is the cmd typed in the cmd line.

However this does not work... the output is something like:

---Starting Python---
 >>>
Traceback (most recent call last):
   File "<string>", line 15, in ?
   File "C:\Python22\lib\code.py", line 307, in interact

console.interact(banner)
   File "C:\Python22\lib\code.py", line 244, in interact

more = self.push(line)
   File "C:\Python22\lib\code.py", line 265, in push

source = "\n".join(self.buffer)
TypeError
:
sequence item 0: expected string, instance found


Any clues on what's wrong here?

- Keith




More information about the Python-list mailing list