How do I convert a PyObject to string in C++?

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

    #1

    How do I convert a PyObject to string in C++?

    I have a PyObject, say 'Hello World' , a string,
    How do I convert it to a string in C++?
    Thanks in advance!
  • js

    #2
    Re: How do I convert a PyObject to string in C++?

    PyString_AsStri ng returns a c string. Just feed it to std::string


    On Tue, Sep 23, 2008 at 11:32 AM, <lixinyi.23@gma il.comwrote:
    I have a PyObject, say 'Hello World' , a string,
    How do I convert it to a string in C++?
    Thanks in advance!
    --

    >

    Comment

    • Aaron \Castironpi\ Brady

      #3
      Re: How do I convert a PyObject to string in C++?

      On Sep 22, 9:32 pm, lixinyi...@gmai l.com wrote:
      I have a PyObject, say 'Hello World' , a string,
      How do I convert it to a string in C++?
      Thanks in advance!
      Look at PyString_AsStri ngAndSize . It gives you a pointer to a buffer
      and a size. Allocate a new one and copy it if you need to modify it,
      or you want a copy that outlives the object version.

      Comment

      Working...