Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So, I have two projects: a library and a console app. In the library, I have the following function declaration:

C++
std::string NewApp::Testing()
{
	char* test[] = {"test", 0};
	PyObject* obj = Python::Py_Arg("test", "test", test);
	std::string s = PyString_AsString(obj);
	return s;
}


Then, in the app, I call the function:

C++
int _tmain(int argc, _TCHAR* argv[])
{
	std::cout << NewApp::Testing();
	return 0;
}


Which all makes a call to the following Python script (which is in the same release directory as the static library):

PERL
def test(wrd):
    return wrd


Yet, for whatever reason, I get the following error every time I run the program:

AttributeError: `module` object has no attribute `test`
Cannot find function "test"


And it's driving me crazy! It knows where the file is but it can't find the function. What could be causing it?? I've gotten embedded Python to work before in another app, yet I still can't get this one to work! Any help is appreciated. Thanks.
Posted
Comments
Ron Beyer 11-Jun-13 20:34pm    
I can't find anything on Py_Arg, are you using this api? http://docs.python.org/2/c-api/arg.html?highlight=pyarg#PyArg_Parse

Are you sure you got the function arguments right? Where are you telling the argument that it should be expecting a string?
RadXPictures 11-Jun-13 22:22pm    
I followed this tutorial: http://docs.python.org/2/extending/embedding.html. My code is identical, except I replaced the args[] with actual string variable names.

1 solution

I can see something here:

C#
std::string NewApp::Testing()
{
    char* test[] = {"test", 0};//Here you have a char* array called 'test' set to the string of characters "test", ending with the null character '0'///
    PyObject* obj = Python::Py_Arg("test", "test", test);// Here you have 3 tests in your Py_Arg, one of which is the char* array.///
    std::string s = PyString_AsString(obj); // string s now = "test", "test", "test".
    return s;
}


And here you 'define' "test" again:

def test(wrd):
    return wrd
Do you know what type 'wrd' is? While I'm not Python literate, this line of code is not working as you think. Are you defining a function, a variable, a list, ???
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900