PyRun_String with Py_single_input to stdout?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • stuart.tett@gmail.com

    PyRun_String with Py_single_input to stdout?

    I'm using PyRun_String with Py_single_input for a python interpreter
    embedded in my application. I'm using Py_single_input . Py_single input
    is what I want, but it seems to output to stdout. Before when I was
    using Py_eval_input I was able to grab the result so I could print it
    in a text box:

    PyObject *resultObject = PyObject_Str( rstring );
    if( resultObject != NULL ) {
    char *string = PyString_AsStri ng( resultObject );
    }

    But Py_eval_input is only for isolated evaluation, not what I want.
    Py_single_input gives "None" for the string.

    I wrote a class that redirects std::cout, but this doesn't work for
    this, I'm guessing because it uses printf to stdout, not cout.

    Anyone know how I can get the string so I can print it in a text box.

  • Gabriel Genellina

    #2
    Re: PyRun_String with Py_single_input to stdout?

    En Mon, 18 Jun 2007 01:45:38 -0300, stuart.tett@gma il.com
    <stuart.tett@gm ail.comescribió :
    I'm using PyRun_String with Py_single_input for a python interpreter
    embedded in my application. I'm using Py_single_input . Py_single input
    is what I want, but it seems to output to stdout. Before when I was
    using Py_eval_input I was able to grab the result so I could print it
    in a text box:
    >
    PyObject *resultObject = PyObject_Str( rstring );
    if( resultObject != NULL ) {
    char *string = PyString_AsStri ng( resultObject );
    }
    >
    But Py_eval_input is only for isolated evaluation, not what I want.
    Py_single_input gives "None" for the string.
    Maybe because it actually returns None?
    I wrote a class that redirects std::cout, but this doesn't work for
    this, I'm guessing because it uses printf to stdout, not cout.
    >
    Anyone know how I can get the string so I can print it in a text box.
    From your description this should be working... try posting some more code
    showing how you call PyRun_String and how you process the result...

    --
    Gabriel Genellina

    Comment

    • stuart.tett@gmail.com

      #3
      Re: PyRun_String with Py_single_input to stdout?

      I found a solution using sys.displayhook here:


      On Jun 18, 4:24 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
      wrote:
      En Mon, 18 Jun 2007 01:45:38 -0300, stuart.t...@gma il.com
      <stuart.t...@gm ail.comescribió :
      >
      I'm using PyRun_String with Py_single_input for a python interpreter
      embedded in my application. I'm using Py_single_input . Py_single input
      is what I want, but it seems to output to stdout. Before when I was
      using Py_eval_input I was able to grab the result so I could print it
      in a text box:
      >
      PyObject *resultObject = PyObject_Str( rstring );
      if( resultObject != NULL ) {
      char *string = PyString_AsStri ng( resultObject );
      }
      >
      But Py_eval_input is only for isolated evaluation, not what I want.
      Py_single_input gives "None" for the string.
      >
      Maybe because it actually returns None?
      No it doesn't. I know the function returns something because when I
      used Py_eval_input, it returned the correct output. The only
      difference is thate Py_string_input outputs using sys.write (stdout)
      >
      I wrote a class that redirects std::cout, but this doesn't work for
      this, I'm guessing because it uses printf to stdout, not cout.
      >
      Anyone know how I can get the string so I can print it in a text box.
      >
      From your description this should be working... try posting some more code
      showing how you call PyRun_String and how you process the result...
      >
      --
      Gabriel Genellina

      Comment

      Working...