473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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!
Sep 23 '08 #1
2 8045
js
PyString_AsString returns a c string. Just feed it to std::string
http://docs.python.org/api/stringObjects.html#l2h-472

On Tue, Sep 23, 2008 at 11:32 AM, <li********@gmail.comwrote:
I have a PyObject, say 'Hello World' , a string,
How do I convert it to a string in C++?
Thanks in advance!
--
http://mail.python.org/mailman/listinfo/python-list
Sep 23 '08 #2
On Sep 22, 9:32*pm, lixinyi...@gmail.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_AsStringAndSize . 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.
Sep 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Peter Kwan | last post by:
Hi, I believe I have discovered a bug in Python 2.3. Could anyone suggest a get around? When I tested my existing Python code with the newly released Python 2.3, I get the following warning: ...
23
by: Hallvard B Furuseth | last post by:
Has someone got a Python routine or module which converts Unicode strings to lowercase (or uppercase)? What I actually need to do is to compare a number of strings in a case-insensitive manner,...
1
by: Nikolai Kirsebom | last post by:
I'm using BOOST to integrate Python into our application. Could someone tell me how I get hold of the C++ object (pointer to the object instance) from a PyObject *. Example: I have defined and...
1
by: Mike Hoegeman | last post by:
I'm in a situation where -- i have a PyObject * that is a instance of an object -- i need to access a subobject of that (PyObject *) that is described to me as a dotted string, e.g.: ...
1
by: Jinming Xu | last post by:
Hello everyone, While embedding my C++ program with Python, I am impeded by the conversion from a Python Tuple to a C++ array. I hope to get some assistance from you guys. I have a sequence...
0
by: elho | last post by:
I called a own python type 'PyType' with a c function and returned it into my python programm - there it fault. It is said that the object has a NULL-Pointer when I try to debug it? Here are the...
1
by: Allen | last post by:
I have the PyObject pointers, and want to set different type of values to them. For example, INT8 nValue1 = 0; INT16 nValue2 = 1; FLOAT32 fValue = 1.0f; PyObject* var1 <= nValue1
0
by: Borse, Ganesh | last post by:
Hi, My following code is failing with an error of "isSizeSmall not function or callable" //--------------------------------------------------- char szExpr; memset(szExpr,'\0',sizeof(szExpr));...
1
by: Simon Posnjak | last post by:
On Mon, May 5, 2008 at 4:16 PM, Jean-Paul Calderone <exarkun@divmod.comwrote: some_module.some_thing(the_string) function is a swig generated function from a C lib. The C lib function expects...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.