473,326 Members | 2,192 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,326 software developers and data experts.

Embedding - getting full error string

Hi,
I'm new to Python. I'm trying to embbed Python in my Windows
application having some success with redirecting the stdin/out to my
windows application using:

In my C++ code I use PyRun_SimpleString to execute this code:

import sys
import mymodule
class LOGwriter :
def write(self, str):
mymodule.printit(str)
sys.stdout = sys.stderr = LOGwriter()

than adding in C++:

static PyMethodDef mymodule_methods[] = {
{"printit", mymodule_printit, METH_VARARGS, "prints"},
{NULL, NULL, 0 ,NULL} /* sentinel */
};

static PyObject *mymodule_printit(PyObject *self, PyObject* args)
{
char *s;
PyArg_ParseTuple(args, "s", &s);
PrintToWindow(s); <-- my function
return NULL;
}
Well it seems to work ok, until a string with quotes arrives (usualy
when an error occurs). When an error occurs it cuts the error string
after the quote, so I always get
File "
and not the full error string, which should be somthing like File
"<string>", line 3... . I've tried all kind of ways around this, yet
with no sucess. Thanks in advance for any help.

Eli
Jul 18 '05 #1
1 1740
static PyObject *mymodule_printit(PyObject *self, PyObject* args)
{
char *s;
PyArg_ParseTuple(args, "s", &s);
PrintToWindow(s); <-- my function
return NULL;
}


One problem is technically you're returning an error from your print
function. You need to return an increfed PyNone:

Py_INCREF(Py_None);
return Py_None;

Otherwise your code looks pretty much like mine does, and it works fine.


Jul 18 '05 #2

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

Similar topics

0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
2
by: Lyn | last post by:
I am trying to embed a picture into a Bound Object Frame (Me!Photograph) with the following code which is based on MS article http://support.microsoft.com/?id=158941: strPathname =...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
2
by: Matt | last post by:
I'm working on a plug-in for an application called DesktopSideBar for Windows. It emulates to some degree the Longhorn sidebar. The SDK for DesktopSideBar supports .NET plug-in development through...
6
by: Edward | last post by:
I have been doing some research about embedding images in HTML using the data URL src method of the format: <img src="/-/data:image/gif;base64,<DATA>"> My question is, how does one generate...
6
by: mistabean | last post by:
Hello, first of all, I am a programming newbie, especially in python... Onwards to the problem, I have been having difficulty embedding a python module into my C/C++ program. (just a test...
1
by: Benke | last post by:
Hello, I'm quite new to Python and embedding python in c++. I'm trying to write a function that i can use to call a python function. It should take 3 arguments, the name of the python file, the...
5
by: Srinidhi | last post by:
I'm trying to embed a report (.rdlc) file in my project. But it always stays as linked. The 'Persistance' property is grayed & always set to 'Linked at compile time'. Upon further inspection i saw...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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.