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

(no subject)

Hi Guys,

I am having problems in the following C API program where myOtim_system is callable from python function. The module is listed below -

static PyObject *
myOptim_system(PyObject *self, PyObject *args)
{
const char *command;
double u0, v0, u1, v1, u2, v2, u3, v3;
int sts;

/* variables */
PyObject *pstr, *pmod, *pdict, *pfunc, *pargs;
char * cstr;
char *dummy = "Test";
char *x = "x = ";
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;

/* convert them to the doubles */
sscanf(command, "%lf %lf %lf %lf %lf %lf %lf %lf", &u0, &v0,
&u1, &v1, &u2, &v2, &u3, &v3);

sts = (int) (u0+v0+u1+v1+u2+v2+u3+v3);

/* trying to call the python program from C */
/*
The module name is test2_module and the function name is cv_calc_func
- get test2_module.cv_calc_func
*/
pmod = PyImport_ImportModule("test2_module");
pdict = PyModule_GetDict(pmod);

/* convert to the PyObject */
pfunc = PyObject_GetAttrString(pmod, "cv_calc_func");
pargs = Py_BuildValue("s", dummy);
pstr = PyEval_CallObject(pfunc, pargs);

PyArg_Parse(pstr, "s", &cstr);
printf("%s\n", cstr);

Py_DECREF(pmod);
Py_DECREF(pstr);
Py_DECREF(pfunc);
Py_DECREF(pargs);
return Py_BuildValue("i", sts);

}

In the same module I am trying to call the python program from C API. That python program is called test2_module.py. It is listed below -

import string

message = 'Hi I am here'

def cv_calc_func(dummy):
s = "warning" + `dummy`
return s
-----
It contains a method called cv_calc_func(). So now the idea must me clear. I would need to communicate bi-directionally, i.e. from python to C and C to python. This example is inspired by the fact that we use the C func from Numerical recepies in C corresponding to lets say some optimization algorithm. So that we don't re-invent the wheel in python. So we call a C API frompython. But in the optimization the objective function value must be returned from a python program, so from C API I should be able to call a python program and then integrate it with my optimization algorithm.

In this example I have tried to use "PyEval_CallObject()" within the "myOptim_system" C API function but it reports memory error. But when I call it from main() it doesn't report any errors.
Just wondering what do I do here?

-regards
Prav
--
_______________________________________________
NEW! Lycos Dating Search. The only place to search multiple dating sites atonce.
http://datingsearch.lycos.com

Jul 18 '05 #1
0 994

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

Similar topics

19
by: gsb | last post by:
HOW TO: Submit a form to PHP with no return? I need to submit a form for file upload to a PHP script but do not want anything returned. That is the TARGET for the form should be like a null...
1
by: Jeff Sandys | last post by:
Can you include a subject with sendmail using smtplib? When I do this (names changed to protect the innocent): import smtplib toadr = "me@myisp.com" frmadr = "myhost@myhost.com" msg = "this...
3
by: Gert-Jan van Middelkoop | last post by:
Hi, I'm using an e-mailform on my website. I would like to make a dropdownmenu with several subjects, so when the e-mail arrives I can immediatly see it's subject. Therefore, this code must...
6
by: Susan | last post by:
Is there any way to take one of the fields from the form and use that as your subject line.. right now I have a default subject line entered - but would rather have the subject be the information...
1
by: kamlai | last post by:
I've written the following codes to include utf-8 wordings in both the subject and the content. $headers = "MIME-Version: 1.0\r\n". "Content-type: text/plain; charset=utf-8\r\n". "From:...
3
by: Laangen_LU | last post by:
Dear Group, my first post to this group, so if I'm on the wrong group, my apologies. I'm trying to send out an email in Chinese lanuage using the mail() function in PHP. Subject and...
3
by: b. dougherty | last post by:
Greetings all- I am trying to extract subject headers from emails that have been saved as text files. The subject headers are in MIME UTF-8 format, and so they appear like this: subject:...
4
by: Alec MacLean | last post by:
Is anyone aware of a size limit imposed on the subject text when using the System.Net.Mail library? I'm getting problems of message not being recieved if the subject exceeds 15 chars. Thx
7
by: plumba | last post by:
I am working on a html form for work, I need to make the Subject of the email which the form produces to be unique each time. The subject is currently hard coded in, in the format of:<form...
5
by: Alan Isaac | last post by:
I have two questions about the "observer pattern" in Python. This is question #1. (I'll put the other is a separate post.) Here is a standard example of the observer pattern in Python:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.